1package xmlnode 2 3import ( 4 "encoding/xml" 5 6 "github.com/ChrisTrenkamp/goxpath/tree" 7) 8 9//XMLNode will represent an attribute, character data, comment, or processing instruction node 10type XMLNode struct { 11 xml.Token 12 tree.NodePos 13 tree.NodeType 14 Parent tree.Elem 15} 16 17//GetToken returns the xml.Token representation of the node 18func (a XMLNode) GetToken() xml.Token { 19 if a.NodeType == tree.NtAttr { 20 ret := a.Token.(*xml.Attr) 21 return *ret 22 } 23 return a.Token 24} 25 26//GetParent returns the parent node 27func (a XMLNode) GetParent() tree.Elem { 28 return a.Parent 29} 30 31//ResValue returns the string value of the attribute 32func (a XMLNode) ResValue() string { 33 switch a.NodeType { 34 case tree.NtAttr: 35 return a.Token.(*xml.Attr).Value 36 case tree.NtChd: 37 return string(a.Token.(xml.CharData)) 38 case tree.NtComm: 39 return string(a.Token.(xml.Comment)) 40 } 41 //case tree.NtPi: 42 return string(a.Token.(xml.ProcInst).Inst) 43} 44