Want to use go to do a statistical SVN code submission tool, similar to STATSVN.
Today, I went to the XML file generated by the Go parsing svn log, I found a example on Go doc, and already included some typical parsing cases, but in divert, there was a problem, there was a paths with multiple path, Each path has its own attributes and values, and it's a great effort to channel properties and values at the same time.
Start with the SVN XML format log demo.
Example
<?xml version= "1.0"?> <log> <logentry revision= "43424" > <AUTHOR&G
t;fukun</author> <date>2015-03-13T11:05:17.341130Z</date> <paths> <path kind= "File" action= "M" >/BigDataPlatform/trunk/application/controllers/Enterpriseajaxapi.php</path> <path kind= " File "action=" M ">/BigDataPlatform/trunk/application/models/ChartDataFormater.php</path> <path kind="
File "action=" M ">/BigDataPlatform/trunk/application/controllers/Mediaajaxapi.php</path> </paths> <msg> abstracting The method of formatting a line chart </msg> </logentry> <logentry revision= "43423" > <author>zhengjin< /author> <date>2015-03-13T11:04:50.450051Z</date> <paths> <path kind= "file" action= "M" >/ bigdataplatform/trunk/public/static/js/mapchart.js</path> </paths> <msg> Map Event Response </msg> < /logentry> </log>
All the other things went well, but it was a bit of trouble parsing the paths. If... Paths []path ' xml: Paths ' ...,
Example
Type Path struct {
Kind string ' xml: ' kind,attr ' '
Action string ' xml: ' action,attr ' '
path string ' xml: ' path '
}
In this case, you can only take the value of a path, but if you use Paths []path ' xml: ' Paths>path ', you can only take action and kind values, the value of path cannot be taken. On the StackOverflow to see a few examples, found that there is a, chardata use, only to know that the original value can also be used to specify. Change the XML definition of path's struct path to ' xml: ', Chardata ', to get value.
Specific struct will not be written, if necessary, you can go to the GOSTATSVN I am developing to see. Hosted in GitHub.
Reference:
Data structures related to representing XML
①type Name struct {
Spaces, local string
}
Local name, space represents the namespace prefix (namespace identifier), the type does not provide any method, the main purpose is to define a type on the XML root element, the variable name must be XMLName, the type is: XML. Name
②attr (attributes), Chardata (character data), Comment (annotation), procinst (processing instructions), and so on. These types are representations of XML standard definitions and are interested in viewing the standard control learning of XML.