Options

XML file import problems

andhildaandhilda Member Posts: 26
Hi there,

First time poster, long time user!

I've this problem with reading child element from a XML file. It woks fine until I start to loop through alle the lines. In the Line segment there's many child elements but I'm not able to read these.

My XML file looks like this:
<InvoiceLine>
		<LineItemNumber>000010</LineItemNumber>
		<GTIN>000000000000245929</GTIN>
		<TradeItemId>
			<TradeItemNumber />
			<TradeItemNumberTypeCode />
		</TradeItemId>
		<ItemDescription>ME HOLZLASUR ML NUSSBAUM            1250</ItemDescription>
		<DeliveredQuantity>
			<Quantity>12.000</Quantity>
			<MeasureUnitQualifier>PCE</MeasureUnitQualifier>
		</DeliveredQuantity>
		<InvoicedQuantity>
			<Quantity>12.000</Quantity>
			<MeasureUnitQualifier>PCE</MeasureUnitQualifier>
		</InvoicedQuantity>
		<LineItemAmount>201.00</LineItemAmount>
		<AdditionalIdentification>
			<BatchNumber />
			<HarmonisedSytemNumber />
			<PromotionalDealNumber />
		</AdditionalIdentification>
		<NetUnitPrice>
			<Price>6.70</Price>
			<UnitPriceBasis>1</UnitPriceBasis>
			<MeasureUnitQualifier>LTR</MeasureUnitQualifier>
		</NetUnitPrice>
		<GrossUnitPrice>
			<Price />
			<UnitPriceBasis />
			<MeasureUnitQualifier />
		</GrossUnitPrice>

and my Code looks like this: (based on XML Import Sample v1.0i)

//Start handling line

LoadNodeList(XMLDocument,XMLNodeList,'InvoiceLine'); // Load nodes <Items><Item></Item><Items> from XML File.
LoadNode(XMLNodeList,XMLNode,0); // Load Node Number 1 (0 = 1) from Node List.

REPEAT // Loop through all Nodes.

  XMLimpIndkøbsFaktura."Faktura nr." := CurrentInvoiceNo;
  EVALUATE(XMLimpIndkøbsFaktura."Linie nr.",XMLNode.selectNodes('LineItemNumber').item(0).text);
  EVALUATE(XMLimpIndkøbsFaktura."Leverandørens varenr.",XMLNode.selectNodes('GTIN').item(0).text);
  EVALUATE(XMLimpIndkøbsFaktura."Leverandørens varetekst",XMLNode.selectNodes('ItemDescription').item(0).text);
  XMLNode := XMLNodeList.nextNode; // Next Node Element

from here I need to read the Quantity node inside the DeliveredQuantity element. I've triede to make an ekstra set of XMLNode, XMLNodelist and but then I only get the first value, in every loop.

Please advise on how to solve this.

Best regards

Andhilda

Comments

  • Options
    DenSterDenSter Member Posts: 8,304
    You're almost there. Create a new node variable called CurrNode, and set it to the DeliveredQuantity node. Now you can access nodes inside there as if they were part of the root. Check out the XML codeunits in standard Navision Commerce Gateway functionality, there are tons of examples in there. You can even use a Navision codeunit to navigate through the nodes. Check out codeunits 6224 and 99008516 for 'Navision-safe' XML navigation, and codeunit 6226 and 99008518 to see how they use it. The two first ones are almost identical, you'd think that they would create just one :).
  • Options
    andhildaandhilda Member Posts: 26
    Hi DenSter,

    Thank you very much for the help. I looked into C.6226 and completly rewrote my code and now it works perfectly.

    Best regards

    Andhilda
  • Options
    DenSterDenSter Member Posts: 8,304
    Cool stuff isnt it :). If you have access to 4.0 it's even easier to do with XMLPorts. No more node navigation code, just map elements fo variables and fields directly.

    Oh one more thing you will run into. Make sure you program type conversion. The XML document holds text values only, so you will have to convert those values into option values, integers, decimals, booleans, etc.
Sign In or Register to comment.