hi everybody!
i have to read an xml-file in navision (so i use the available automation-variables
) ... but this xml-file can have a variable tree ... so i have to find out if a node has childnodes or not (to choose if i have to read the childnodes text ... or to look at the next node of my nodelist
) ...
but how can i find out if a node has childnodes or just some attributes (which just are some text)? cause 'hasChildNodes' returns 'true' in both cases
thanks in advance!
oliver
Comments
you can download MSXML 4 SP2 from the URL:
"http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&DisplayLang=en".
This package includes the XML SDK where you can find more informations about using MSXML.
Now to your question.
You can use the following model for walking through the DOM.
---snipp ---
IF Node.hasChildNodes THEN
FOR int := 0 TO (Node.childNodes.length - 1) DO BEGIN
.....
END;
---snapp ---
With this example "Node.childNodes" returns a nodeList and you can proof the length of the nodeList (means the individual items).
A way to address the childNodes directly is, to use "item" of the nodeList.
IF Node.hasChildNodes THEN BEGIN
NoOfItems := Node.childNodes.length;
ActNode := Node.childNodes.item(25) => to request the 25. child
END;
Another way to select Nodes is by using the command "selectNodes" or
"selectSingleNode" with an XPath-Query.
IF InDOM.selectNodes('//Books/Book').length > 0 THEN
ActNode := InDOM.selectSingleNode('//Books/Book[2]'); => to choose the second Book-Node within the Books-Element.
Good luck ...
Stefan
it works pretty fine!
cu,
oliver