@@ -12,6 +12,7 @@ type XMLParser struct {
1212 loopElements map [string ]bool
1313 resultChannel chan * XMLElement
1414 skipElements map [string ]bool
15+ attrOnlyElements map [string ]bool
1516 skipOuterElements bool
1617 xpathEnabled bool
1718 scratch * scratch
@@ -22,12 +23,13 @@ type XMLParser struct {
2223func NewXMLParser (reader * bufio.Reader , loopElements ... string ) * XMLParser {
2324
2425 x := & XMLParser {
25- reader : reader ,
26- loopElements : map [string ]bool {},
27- resultChannel : make (chan * XMLElement , 256 ),
28- skipElements : map [string ]bool {},
29- scratch : & scratch {data : make ([]byte , 1024 )},
30- scratch2 : & scratch {data : make ([]byte , 1024 )},
26+ reader : reader ,
27+ loopElements : map [string ]bool {},
28+ attrOnlyElements : map [string ]bool {},
29+ resultChannel : make (chan * XMLElement , 256 ),
30+ skipElements : map [string ]bool {},
31+ scratch : & scratch {data : make ([]byte , 1024 )},
32+ scratch2 : & scratch {data : make ([]byte , 1024 )},
3133 }
3234
3335 // Register loop elements
@@ -49,6 +51,13 @@ func (x *XMLParser) SkipElements(skipElements []string) *XMLParser {
4951
5052}
5153
54+ func (x * XMLParser ) ParseAttributesOnly (loopElements ... string ) * XMLParser {
55+ for _ , e := range loopElements {
56+ x .attrOnlyElements [e ] = true
57+ }
58+ return x
59+ }
60+
5261// by default skip elements works for stream elements childs
5362// if this method called parser skip also outer elements
5463func (x * XMLParser ) SkipOuterElements () * XMLParser {
@@ -136,7 +145,9 @@ func (x *XMLParser) parse() {
136145 continue
137146 }
138147
139- element = x .getElementTree (element )
148+ if _ , only := x .attrOnlyElements [element .Name ]; ! only {
149+ element = x .getElementTree (element )
150+ }
140151 x .resultChannel <- element
141152 if element .Err != nil {
142153 return
0 commit comments