Test each attribute of an XML File

cschueller
Member Posts: 6
Hello !
I'm facing a problem while I'm reading an XML file with the XMLDOM automation. My file contains lot of attributes for one tag, for example :
I'd like to find a way to browse the attributes, because some are always filled but some are not always in the file, and if I try to get an attribute which doesn't exist, I get a nice error...
My code is :
Here if the "delivery-date" attribute is not in the "order" tag then NAV throw me an error.
Thanks for your help !
Cédric
I'm facing a problem while I'm reading an XML file with the XMLDOM automation. My file contains lot of attributes for one tag, for example :
<order client-id="1" order-external="xxxyyy123" order-id="1188333" customer-id="212221" customer-group="9999" short-name="HUFR05" order-date="24.05.2011" order-type="1" order-release-code="0" reference1="BA 11-1398" reference2="85 LA SAGESSE MS" > <position client-id="1" customer-id="212221" order-id="1188333" order-position="10" item-id="0162993-0" item- group="710" description1="Universal-Geschirrstapler USTH/ 57-28" description2="Edelstahl" ordered-quantity="1" desired-delivery-date="28.06.2011" delivery-date="28.06.2011" open-quantity="1" delivered-quantity="0" invoiced-quantity="0" quantity-unit-code="1" quantity-unit="Stck" gross-price="2142" value="963,9" unit-price="963,9" price-unit-code="0" discount1="55" discount2="0" vat="0" user="JBR" modification-date="24.05.2011"/> </order>
I'd like to find a way to browse the attributes, because some are always filled but some are not always in the file, and if I try to get an attribute which doesn't exist, I get a nice error...
My code is :
CREATE(XMLDomDoc); XMLDomDoc.load(RecPEDIVendorSetup."WINEDI File Folder" + '\' + RecLFile.Name); XMLNodeList := XMLDomDoc.selectNodes('envelope/request/response/orders/order'); XMLNodeCurr := XMLNodeList.nextNode(); WHILE NOT ISCLEAR(XMLNodeCurr) DO BEGIN XMLAttributes := XMLNodeCurr.attributes; IF RecLPurchaseHeader.GET(RecLPurchaseHeader."Document Type"::Order, XMLAttributes.getNamedItem('order-external').text) THEN BEGIN IF EVALUATE(DatLDelivery, XMLAttributes.getNamedItem('delivery-date').text) THEN; //*** Some more code ***// end; XMLNodeCurr := XMLNodeList.nextNode(); END;
Here if the "delivery-date" attribute is not in the "order" tag then NAV throw me an error.
Thanks for your help !
Cédric
0
Answers
-
i had the same problem not too long ago, and made a function that will give you the value of an attribute if available, otherwise it'll return an empty text
PROCEDURE GetAttribFromNode(Node : Automation :'Microsoft XML, v6.0.IXMLDOMNode ; AttribName : Text[50]) : Text[1024]; VAR Element : Automation : Microsoft XML, v6.0.IXMLDOMElement; Attrib : Automation : Microsoft XML, v6.0.IXMLDOMAttribute; BEGIN //You can only get the attribute if you treat a node as an element Element := Node ; Attrib := Element.getAttributeNode(AttribName) ; //variable is not set if attribute doesn't exist IF NOT(ISCLEAR(Attrib)) THEN EXIT(Attrib.nodeValue) ; END;
0 -
Thanks a lot, but in the meantime I found myself a solution ! Which is :
XMLAttributes := XMLNodeCurr.attributes; i := 0 WHILE i < XMLAttributes.length DO BEGIN case XMLAttributes.item(i).nodeName of 'order-external': CodLOrderno := XMLAttributes.item(i).text; 'delivery-date': IF not EVALUATE(DatLDelivery, XMLAttributes.item(i).text) THEN datldelivery := 0D; 'order-id' : CodLOrderId := XMLAttributes.item(i).text; end; i += 1; END;
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