read xml-file - can't find out if node has childnodes

OliverT
Member Posts: 37
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
i have to read an xml-file in navision (so i use the available automation-variables


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

0
Comments
-
hi oliver,
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 ...
Stefan0 -
wow ... thanks!
it works pretty fine!
cu,
oliver0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions