Go resolves svn log-generated XML-formatted file _golang

Source: Internet
Author: User
Tags data structures svn

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.