如何解析GO中忽略嵌套元素的巨大xml?

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?

Typically it is best to use XML decoder for large XML, it uses the stream and Go with selective binding (like WantThisElement>Bar) then XML decoder follows that path.

Let's use XML content from your question to create an example.

XML Content:

<Report>
    <ElementOne Blah="bleh">
        <IgnoreElement>
            <Foo>
                <FooValue>example foo value</FooValue>
            </Foo>
        </IgnoreElement>

        <WantThisElement>
            <Bar Baz="test">
                 <BarValue>example bar value 1</BarValue>
            </Bar>
            <Bar Baz="test2">
                <BarValue>example bar value 2</BarValue>
            </Bar>
        </WantThisElement>
    </ElementOne>
</Report>

Structures:

type Report struct {
    XMLName    xml.Name `xml:"Report"`
    ElementOne ElementOne
}

type ElementOne struct {
    XMLName xml.Name `xml:"ElementOne"`
    Blah    string   `xml:"Blah,attr"`
    Bar     []Bar    `xml:"WantThisElement>Bar"`
}

type Bar struct {
    XMLName  xml.Name `xml:"Bar"`
    Baz      string   `xml:"Baz,attr"`
    BarValue string   `xml:"BarValue"`
}

Play Link: https://play.golang.org/p/26xDkojeUp