Jump to content

Read XML file


Recommended Posts

HelloI 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 OpenXMLDocumentVar Name DataType Subtype LengthNej FileName Text 1024Ja XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument IF ISCLEAR(XMLDocument) THEN CREATE(XMLDocument);XMLDocument.load(FileName);Funktion LoadNodeListVar Name DataType Subtype LengthNej XMLDocument Automation 'Microsoft XML, version 2.0'.DOMDocument Ja XMLNodeList Automation 'Microsoft XML, version 2.0'.IXMLDOMNodeList Nej ElementName Text 1024XMLNodeList := XMLDocument.getElementsByTagName(ElementName);Funktion LoadNodeVar Name DataType Subtype LengthNej 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 okTotNumbOfRecsB = 5 Not ok, why do I not get 3 first time and then 2.I want to get following recordsetA 70000A 70001A 70002B 70003B 70004But I get following recordsetA 70000A 70001A 70002A 70003A 70004B 70000B 70001B 70002B 70003B 70004Help me.

Link to post
Share on other sites

What on earth is that?What language are you programming this in? Whatever the case, is XSLT an option? If so, consider using it. If not.... I hope you know a forum that actually deals not with XML, but with the language you're using to read the XML.

Link to post
Share on other sites
...When a run this code then I get following values:TotNumbOfRecsA = 2 okTotNumbOfRecsB = 5 Not ok, why do I not get 3 first time and then 2....
Well, I don't know Navision AT ALL :), but from the look of that nested REPEAT-UNTIL syntax, and from your expectation to get 3 then 2, the intent is to address Items A on the first pass and items B on the second pass. But from the XML structure that is not going to happen. The nested code
  LoadNodeList(XMLDocument,XMLNodeList2,'Report/Items/Item');  TotNumbOfRecsB := XMLNodeList2.length;

looks to me as if it will select all the item elements each time, because

'/Report/Items/Item'

is the collection of all 5 items: 3 from A, and 2 from B.To select either items from A or B, you would need the xpath:

"/Report/Items[@Type='A']/Item"

which selects 3 items, and

"/Report/Items[@Type='B']/Item"

which selects 2 items.EDIT: In fact, from this line in the outer REPEAT-UNTIL:

XMLNode := XMLNodeList.nextNode;

I think you probably intended to use XMLNode in the inner REPEAT-UNTIL, but you do not do so. Also Type does not appear to be used after this line:

EVALUATE(Type,(XMLNode.attributes().getNamedItem('Type').text));

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...