How to use go to parse files in xml format generated by svn log
How to use go to parse svn log generated xml format files, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Want to use go to do a statistical svn code submission tool, similar to statsvn.
Today, we use go to parse the xml format file generated by svn log, and find an Example on go doc, which already includes some typical parsing cases, but we still encounter problems when we follow the picture. There are multiple path under a paths, and each path has its own attributes and values. It takes a lot of effort to simultaneously channel attributes and values.
Let's start with the demo of log in svn xml format.
Example
Fukun2015-03-13T11:05:17.341130Z/BigDataPlatform/trunk/application/controllers/Enterpriseajaxapi.php/BigDataPlatform/trunk/application/models/ChartDataFormater.php/BigDataPlatform/trunk/application/controllers/Mediaajaxapi.php abstracts the method of formatting line chart zhengjin2015-03-13T11:04:50.450051Z/BigDataPlatform/trunk/public/static/js/mapChart.js map event response
Parsing everything else went well, but I had some trouble parsing the paths block. 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 way, only one path can be obtained, but if you use Paths [] Path `xml: "paths > path" `, you can only get the values of Action and Kind, but not the value of path. After looking at a few more examples on stackoverflow, I found that there was a usage of chardata. Only then did I know that the specified value could still be used in this way. Change the xml definition of Path's struct Path to `xml: ", chardata" `, and you can get the value smoothly.
Reference:
Data structures related to representing XML
① type Name struct {
Space, Local string
}
Local represents the local name, and Space represents the namespace prefix (namespace identifier). This type does not provide any method. The main purpose is to define a type on the root element of XML. The variable name must be XMLName, and the type must be: xml.Name.
② Attr (attribute), CharData (character data), Comment (comment), ProcInst (processing instruction), etc. These types are all representations defined by the XML standard. If you are interested, you can check out the standard comparison learning of XML.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.