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.
Javaid Sethi
0
Answers
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..... :-k
I have to do this to solved the problem.
EVALUATE(Type,(XMLNode.attributes().getNamedItem('Type').text));
LoadNodeList(XMLDocument,XMLNodeList2,
'Report/Items[@Type="'+Type+'"]/Item');
bye