Documentation ¶
Index ¶
- type XMLNode
- func (xn *XMLNode) CurrentKey() string
- func (xn *XMLNode) Elements() []string
- func (xn *XMLNode) FindByFullPath(path string) []XMLNode
- func (xn *XMLNode) FindByKey(key string) []XMLNode
- func (xn *XMLNode) FindByKeys(keys ...string) []XMLNode
- func (xn *XMLNode) FindByPath(path string) []XMLNode
- func (xn *XMLNode) IsLeaf() bool
- func (xn *XMLNode) LeafNodes() []XMLNode
- func (xn *XMLNode) LeafPaths() []string
- func (xn *XMLNode) PrintXML()
- func (xn *XMLNode) ToBool() (bool, error)
- func (xn *XMLNode) ToFloat64() (float64, error)
- func (xn *XMLNode) ToInt() (int, error)
- func (xn *XMLNode) ToMap() (mxj.Map, error)
- func (xn *XMLNode) ToString() (string, error)
- func (xn *XMLNode) ToStruct(structPtr interface{}) error
- func (xn *XMLNode) ToTime() (time.Time, error)
- func (xn *XMLNode) ValueType() reflect.Kind
- func (xn *XMLNode) XML() ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type XMLNode ¶
type XMLNode struct { Value interface{} Path string }
XMLNode is wrapper to mxj map. It can traverse the xml to get the data. NOTE:
All attributes will also become a node with key '-attributesName'. And tags with attributes, their value will become a node with key '#text'.
Ex:
<ProductName sku="ABC"> This will become node also. </ProductName>
Will become:
map[string]interface{ "-sku": "ABC", "#text": "This will become node also.", }
func GenerateXMLNode ¶
GenerateXMLNode generate an XMLNode object from the xml response body.
func (*XMLNode) CurrentKey ¶
CurrentKey return the key (tag) for the current node. Root node has empty key.
func (*XMLNode) FindByFullPath ¶
FindByFullPath get the element data by absolute path. Path is separated by '.', ex: "Tag1.Tag2.Tag3". If current node have path "A.B.C", and query path is "A.B.C.D.E",
then the method will search elements in current node with path "D.E".
The method return a list XMLNode, each node represents all the sub-elements
of the match key. The nodes then can be use to traverse deeper individually.
func (*XMLNode) FindByKey ¶
FindByKey get the element data by any key (tag) in any depth. The method return a list XMLNode, each node represents all the sub-elements
of the match key. The nodes then can be use to traverse deeper individually.
func (*XMLNode) FindByKeys ¶
FindByKeys get the element data by any keys (tag) in any depth. Subsequential key need to be child of previous. The method return a list XMLNode, each node represents all the sub-elements
of the match key. The nodes then can be use to traverse deeper individually.
Ex:
If current node have path "A.B.C.D.E" and "A.B2.C2.D2.E", then node.FindByKeys("B", "E") will return nodes E under first path.
func (*XMLNode) FindByPath ¶
FindByPath get the element data by path string. Path is relative to the current XMLNode. Path need to be start with direct sub node of current node. Path is separated by '.', ex: "Tag1.Tag2.Tag3". If current node is "A", and has sub path "B.C", then query on "B.C" will
return node C. But Query on "C" will return empty nodes.
The method return a list XMLNode, each node represents all the sub-elements
of the match key. The nodes then can be use to traverse deeper individually.
func (*XMLNode) PrintXML ¶
func (xn *XMLNode) PrintXML()
PrintXML print the xml with two space indention.
func (*XMLNode) ToBool ¶
ToBool convert the node value to bool. If value is not valid bool, an error will be returned.
func (*XMLNode) ToFloat64 ¶
ToFloat64 convert the node value to float64. If value is not valid float64, an error will be returned.
func (*XMLNode) ToInt ¶
ToInt convert the node value to int. If value is not valid int, an error will be returned.
func (*XMLNode) ToMap ¶
ToMap convert the node value to a mxj map. If fail to convert, an error will be returned. Tags have no sub tag, but have attributes is also a map. Attributes of the tag has key '-attributesName'. Tags' value has key '#test'. Ex:
<MessageId MarketplaceID="ATVPDKDDIKX0D" SKU="24478624"> 173964729 </MessageId>
After to map,
map[string]string{ "-MarketplaceID": "ATVPDKDDIKX0D", "-SKU": "24478624", "#text": "173964729", }
func (*XMLNode) ToString ¶
ToString convert the node value to string. If value is not valid string, an error will be returned.
func (*XMLNode) ToStruct ¶
ToStruct unmarshal the node value to struct. If value can not be unmarshal, an error will returned. ToStruct use json tag to unmarshal the map. Ex: To unmarshal the tag:
<MessageId MarketplaceID="ATVPDKDDIKX0D" SKU="24478624"> 173964729 </MessageId>
Can use struct:
msgID := struct { MarketplaceID string `json:"-MarketplaceID"` SKU string `json:"-SKU"` ID string `json:"#text"` }{}
func (*XMLNode) ToTime ¶
ToTime convert the node value to timestamp. If value is not valid timestamp, an error will be returned.
func (*XMLNode) XML ¶
XML return the raw xml data. If current node has key, use it as root node tag. If current node doest has key, and only have one child node, then the child
node's key will become root node tag.
If current node doest has key, and have more than one child node, then
the a default tag <doc> will use as root tag.