decoder := xml.NewDecoder(xmlReader) for { token, err := decoder.Token() if err == io.EOF { break } if element, ok := token.(xml.StartElement); ok && element.Name.Local == "skipMe" { if err := decoder.Skip(); err != nil { log.Fatal(err) } } }
decoder := xml.NewDecoder(xmlReader) for { token, err := decoder.Token() if err == io.EOF { break } if element, ok := token.(xml.StartElement); ok { for _, attr := range element.Attr { if attr.Name.Local == "skip" && attr.Value == "true" { if err := decoder.Skip(); err != nil { log.Fatal(err) } break } } } }This code will read through an XML document and skip over any elements that have an attribute with the name "skip" and value "true". In both of these examples, we are using the encoding/xml package.