XML file import problems

andhilda
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:
and my Code looks like this: (based on XML Import Sample v1.0i)
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
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
0
Comments
-
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
.
0 -
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
Andhilda0 -
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.0
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