I have this XML, for example:
<Report>
...
<ElementOne Blah="bleh">
<IgnoreElement>
<Foo>
...
</Foo>
</IgnoreElement>
<WantThisElement>
<Bar Baz="test">
...
</Bar>
<Bar Baz="test2">
...
</Bar>
</WantThisElement>
</ElementOne>
...
</Report>
And I'm parsing this with encode/xml:
...
decoder := xml.NewDecoder(resp.Body)
Mystruct := MyStruct{}
for {
t, _ := decoder.Token()
if t == nil {
break
}
switch se := t.(type) {
case xml.StartElement:
if se.Name.Local == "ElementOne" {
decoder.DecodeElement(&Mystruct, &se)
}
}
...
type MyStruct struct{
Blah string
Bar []Bar
}
type Bar struct{
Baz string
...
}
I'm not sure if it is the best way to do it and I don't know if the decoder.DecodeElement(...) ignoring the nested elements that I don't want to parse. I want to increase perfomance with low memory cost. What the best way to parser these huge XML files?