Read a XML file

jas
Member Posts: 9
Hello
I want to read this xml file in Navision program.
<?xml version="1.0"?>
<Report>
<Items Type = "A">
<Item No = "70000">
<Description>Side Panel</Description>
<UnitPrice>30,70</UnitPrice>
</Item>
<Item No = "70001">
<Description>Base</Description>
<UnitPrice>40,30</UnitPrice>
</Item>
<Item No = "70002">
<Description>Top Panel</Description>
<UnitPrice>28,70</UnitPrice>
</Item>
</Items>
<Items Type = "B">
<Item No = "70003">
<Description>Side Panel B</Description>
<UnitPrice>30,70</UnitPrice>
</Item>
<Item No = "70004">
<Description>Base B</Description>
<UnitPrice>40,30</UnitPrice>
</Item>
</Items>
</Report>
Starting with this code:
OpenXMLDocument(FileName,XMLDocument);
LoadNodeList(XMLDocument,XMLNodeList,'Report/Items');
TotNumbOfRecsA := XMLNodeList.length;
LoadNode(XMLNodeList,XMLNode,0);
REPEAT
EVALUATE(Type,(XMLNode.attributes().getNamedItem('Type').text));
LoadNodeList(XMLDocument,XMLNodeList2,'Report/Items/Item');
TotNumbOfRecsB := XMLNodeList2.length;
LoadNode(XMLNodeList2,XMLNode2,0);
REPEAT
EVALUATE(No,(XMLNode2.attributes().getNamedItem('No').text));
EVALUATE(Description,(XMLNode2.selectNodes('Description').item(0).text));
EVALUATE(UnitPrice,(XMLNode2.selectNodes('UnitPrice').item(0).text));
XMLNode2 := XMLNodeList2.nextNode;
UNTIL ISCLEAR(XMLNode2);
XMLNode := XMLNodeList.nextNode;
UNTIL ISCLEAR(XMLNode);
Funktion OpenXMLDocument
Var Name DataType Subtype Length
Nej FileName Text 1024
Ja XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument
IF ISCLEAR(XMLDocument) THEN
CREATE(XMLDocument);
XMLDocument.load(FileName);
Funktion LoadNodeList
Var Name DataType Subtype Length
Nej XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument
Ja XMLNodeList Automation 'Microsoft XML, version 2.0'.IXMLDOMNodeList
Nej ElementName Text 1024
XMLNodeList := XMLDocument.getElementsByTagName(ElementName);
Funktion LoadNode
Var Name DataType Subtype Length
Nej XMLNodeList Automation 'Microsoft XML, version 2.0'.IXMLDOMNodeList
Ja XMLNode Automation 'Microsoft XML, version 2.0'.IXMLDOMNode
Nej RecordIndex Integer
XMLNode := XMLNodeList.item(RecordIndex);
When a run this code then I get following values:
TotNumbOfRecsA = 2 ok
TotNumbOfRecsB = 5 Not ok, why do I not get 3 first time and then 2.
I want to get following recordset
A 70000
A 70001
A 70002
B 70003
B 70004
But I get following recordset
A 70000
A 70001
A 70002
A 70003
A 70004
B 70000
B 70001
B 70002
B 70003
B 70004
Help me.
I want to read this xml file in Navision program.
<?xml version="1.0"?>
<Report>
<Items Type = "A">
<Item No = "70000">
<Description>Side Panel</Description>
<UnitPrice>30,70</UnitPrice>
</Item>
<Item No = "70001">
<Description>Base</Description>
<UnitPrice>40,30</UnitPrice>
</Item>
<Item No = "70002">
<Description>Top Panel</Description>
<UnitPrice>28,70</UnitPrice>
</Item>
</Items>
<Items Type = "B">
<Item No = "70003">
<Description>Side Panel B</Description>
<UnitPrice>30,70</UnitPrice>
</Item>
<Item No = "70004">
<Description>Base B</Description>
<UnitPrice>40,30</UnitPrice>
</Item>
</Items>
</Report>
Starting with this code:
OpenXMLDocument(FileName,XMLDocument);
LoadNodeList(XMLDocument,XMLNodeList,'Report/Items');
TotNumbOfRecsA := XMLNodeList.length;
LoadNode(XMLNodeList,XMLNode,0);
REPEAT
EVALUATE(Type,(XMLNode.attributes().getNamedItem('Type').text));
LoadNodeList(XMLDocument,XMLNodeList2,'Report/Items/Item');
TotNumbOfRecsB := XMLNodeList2.length;
LoadNode(XMLNodeList2,XMLNode2,0);
REPEAT
EVALUATE(No,(XMLNode2.attributes().getNamedItem('No').text));
EVALUATE(Description,(XMLNode2.selectNodes('Description').item(0).text));
EVALUATE(UnitPrice,(XMLNode2.selectNodes('UnitPrice').item(0).text));
XMLNode2 := XMLNodeList2.nextNode;
UNTIL ISCLEAR(XMLNode2);
XMLNode := XMLNodeList.nextNode;
UNTIL ISCLEAR(XMLNode);
Funktion OpenXMLDocument
Var Name DataType Subtype Length
Nej FileName Text 1024
Ja XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument
IF ISCLEAR(XMLDocument) THEN
CREATE(XMLDocument);
XMLDocument.load(FileName);
Funktion LoadNodeList
Var Name DataType Subtype Length
Nej XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument
Ja XMLNodeList Automation 'Microsoft XML, version 2.0'.IXMLDOMNodeList
Nej ElementName Text 1024
XMLNodeList := XMLDocument.getElementsByTagName(ElementName);
Funktion LoadNode
Var Name DataType Subtype Length
Nej XMLNodeList Automation 'Microsoft XML, version 2.0'.IXMLDOMNodeList
Ja XMLNode Automation 'Microsoft XML, version 2.0'.IXMLDOMNode
Nej RecordIndex Integer
XMLNode := XMLNodeList.item(RecordIndex);
When a run this code then I get following values:
TotNumbOfRecsA = 2 ok
TotNumbOfRecsB = 5 Not ok, why do I not get 3 first time and then 2.
I want to get following recordset
A 70000
A 70001
A 70002
B 70003
B 70004
But I get following recordset
A 70000
A 70001
A 70002
A 70003
A 70004
B 70000
B 70001
B 70002
B 70003
B 70004
Help me.
Javaid Sethi
0
Answers
-
Mind you im not an XML wiz, but
LoadNodeList(XMLDocument,XMLNodeList2,'Report/Items/Item');
TotNumbOfRecsB := XMLNodeList2.length;
LoadNode(XMLNodeList2,XMLNode2,0);
I dont think this Nodelist2 knows anything about your previous
Nodelist, therefore wont be able to count only within your repeat range..... :-k0 -
Hi
I have to do this to solved the problem.
EVALUATE(Type,(XMLNode.attributes().getNamedItem('Type').text));
LoadNodeList(XMLDocument,XMLNodeList2,
'Report/Items[@Type="'+Type+'"]/Item');
byeJavaid Sethi0
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