user function XPGChArr()
Local cXML := ""
Local oXML
Local aChildren := {}
oXML := TXMLManager():New()
cXML += '<book isNew="true">' + CRLF
cXML += ' <title>A Clash of Kings</title>' + CRLF
cXML += ' <author>George R. R. Martin</author>' + CRLF
cXML += ' <price>9.99</price>' + CRLF
cXML += ' <origin>US</origin>' + CRLF
cXML += '</book>' + CRLF
if !oXML:Parse( cXML )
conout( "Errors on Parse!" )
return
endif
// Vai exibir
// aChildren -> ARRAY ( 4) [...]
// aChildren[1] -> ARRAY ( 3) [...]
// aChildren[1][1] -> C ( 5) [title]
// aChildren[1][2] -> C ( 11) [/book/title]
// aChildren[1][3] -> C ( 16) [A Clash of Kings]
// aChildren[2] -> ARRAY ( 3) [...]
// aChildren[2][1] -> C ( 6) [author]
// aChildren[2][2] -> C ( 12) [/book/author]
// aChildren[2][3] -> C ( 19) [George R. R. Martin]
// aChildren[3] -> ARRAY ( 3) [...]
// aChildren[3][1] -> C ( 5) [price]
// aChildren[3][2] -> C ( 11) [/book/price]
// aChildren[3][3] -> C ( 4) [9.99]
// aChildren[4] -> ARRAY ( 3) [...]
// aChildren[4][1] -> C ( 6) [origin]
// aChildren[4][2] -> C ( 12) [/book/origin]
// aChildren[4][3] -> C ( 2) [US]
aChildren := oXML:XPathGetChildArray( "/book" )
varinfo( "aChildren", aChildren )
// Vai exibir
// aChildren -> ARRAY ( 0) [...]
aChildren := oXML:XPathGetChildArray( "/book/title" )
varinfo( "aChildren", aChildren )
// Vai exibir
// aChildren -> ARRAY ( 0) [...]
aChildren := oXML:XPathGetChildArray( "/movie" )
varinfo( "aChildren", aChildren )
return
|