Traversing XMLFile using XMLNode DotNet Obj
jordi79
Member Posts: 285
Hi,
I am attempting to open an xml file and checking out the contents in the file. This works beautifully when the file has not xmlns name space, but once there is a xmlns name space definition, then I cannot traverse the xml file.
My code:
The XML File with xmlns:
The xml file without xmlns:
I am attempting to open an xml file and checking out the contents in the file. This works beautifully when the file has not xmlns name space, but once there is a xmlns name space definition, then I cannot traverse the xml file.
My code:
CLEARALL(); XMLDoc := XMLDoc.XmlDocument; FileName := 'c:\temp\temp1.xml'; FileName := FileMgmt.UploadFileSilent(FileName); IF NOT EXISTS(FileName) THEN EXIT; f.OPEN(FileName); f.TEXTMODE(TRUE); f.CREATEINSTREAM(FileInStream); XMLDoc.Load(FileInStream); RootNode := XMLDoc.DocumentElement; MESSAGE(RootNode.Name + '-' + RootNode.InnerText); FindNode(RootNode, 'invoice', Node); IF NOT ISNULL(Node) THEN BEGIN MESSAGE(Node.Name + '-' + Node.InnerText); // this line is skipped if the xml file has xmlns, because the node cannot be found... END;
The XML File with xmlns:
<content xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <invoice> <id>inv_001</id> <name>user name</name> </invoice> </content>
The xml file without xmlns:
<content> <invoice> <id>inv_001</id> <name>user name</name> </invoice> </content>
0
Comments
-
The problem is the SelectSingleNode function used by the FindNode function. There are examples from Microsoft how to remove the namespaces prior to parsing the file. You can also call the function yourself and use a proper namespace manager and XPath or use other functions of the dll to get the xml node.
You can find a lot information if you google for XML namespaces and SelectSingleNode and an example how to handle it in the MSDN: http://msdn.microsoft.com/de-de/library/system.xml.xmlnode.selectsinglenode(v=vs.110).aspx
The automation/dll itself is fully capable of handling namespaces and we do support it in Anveo EDI Connect.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions