I have a lot of XML documents that have sections in that contain tags that can be of any name but will contain type,minOccurs,maxOccurs and have a description inside it. For instance name,description,definition and id below.
<?xml version="1.0" encoding="utf-8"?>
<topLevel name="insight">
<description>description number1</description>
<rights>
<privLevel>user</privLevel>
</rights>
<method name="graphCreate">
<description>graphCreate API</description>
<rights></rights>
<request>
<params>
<name type="xs:string" minOccurs="1" >
<description>A friendly name to identify the graph</description>
</name>
<description type="xs:string" minOccurs="1" >
<description>Detailed description of the graph</description>
</description>
<definition type="graphDefinition" minOccurs="1" maxOccurs="1">
<description>Specify the graph definition. i.e how this graph should be built.</description>
</definition>
</params>
</request>
<response>
<params>
<id type="xs:unsignedInt" minOccurs="1" >
<description>graph identifier.</description>
</id>
</params>
</response>
</method>
</topLevel>
Whats the best way to parse this. So far I have but can't work out how to dynamically generate the struct to stuff this into. Any suggestions?
type topLevel struct {
Description string `xml:"description"`
Rights rights `xml:"rights"`
Method []method `xml:"method"`
}
type method struct {
Name string `xml:"name,attr"`
Description string `xml:"description"`
Rights []right `xml:"rights"`
}
type right struct {
Right string `xml:"right"`
}
type request struct {
}
type rights struct {
PrivLevel string `xml:"privLevel"`
}