O método adiciona um nó filho ao nó apontado pela expressão XPath.
Sintaxe
XPathAddNode( < cXPathExpr >, < cNodeName >, < cNodeValue > )
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
---|---|---|---|---|
cXPathExpr | caractere | Expressão XPath. | X | |
cNodeName | caractere | Nome do nó desejado | X | |
cNodeValue | caractere | Valor do nó desejado | X |
Retorno
Nome | Tipo | Descrição |
---|---|---|
lRet | lógico | Verdadeiro (.T.) caso tenha sido possivel adicionar. Falso (.F.) caso contrário. |
Observações
- O valor contido em <cXPathExpr> deve ser informado de acordo com o case no XML. Esta implementação é case sensitive.
Exemplos
Exemplo 1
user function XPAddN() 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 ".F." conout( oXML:XPathAddNode( "/book", "", "no" ) ) // Vai exibir ".T." conout( oXML:XPathAddNode( "/book", "hardcover", "no" ) ) // Vai exibir // aChildren -> ARRAY ( 5) [...] // 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[5] -> ARRAY ( 3) [...] // aChildren[5][1] -> C ( 9) [hardcover] // aChildren[5][2] -> C ( 15) [/book/hardcover] // aChildren[5][3] -> C ( 2) [no] aChildren := oXML:XPathGetChildArray( "/book" ) varinfo( "aChildren", aChildren ) return
Visão Geral
Import HTML Content
Conteúdo das Ferramentas