XMLDOM - parsing xml with namespaces

jensthomsen
Member Posts: 173
I'm reading a XML with XMLDOM3.0. The XML looks like the image attached. What would be the right way to browse through the XML to get the information from say the 'JGTIdent'? My problem is, that the namespace 'cec' can be different from file to file (CEC, CBC etc) - can I somehow suppress the namespace when parcing the file?
0
Comments
-
Yes, im using XML 6.0 and from this forum build this function.
OpenExistingXml(VAR vPtFilePath : Text[250];VAR vPxmlDoc : Automation "'Microsoft XML, v6.0'.DOMDocument60";PbRemoveNameSpaces : Boolean LfXml.OPEN(vPtFilePath); LfXml.CREATEINSTREAM(LisStream); IF ISCLEAR(vPxmlDoc) THEN BEGIN CREATE(vPxmlDoc); END; vPxmlDoc.load(LisStream); LfXml.CLOSE; CLEAR(LfXml); IF (STRPOS(LOWERCASE(vPtFilePath), '.nons.') > 0) THEN BEGIN PbRemoveNameSpaces := TRUE; END; IF (PbRemoveNameSpaces) THEN BEGIN //http://www.mibuso.com/forum/viewtopic.php?f=5&t=16627&hilit=transformNodeToObject LrCompanyInfo.Picture.CREATEOUTSTREAM(LosStylesheet); LrCompanyInfo.Picture.CREATEINSTREAM(LisStylesheet); LosStylesheet.WRITETEXT('<?xml version="1.0" encoding="UTF-8"?>'); LosStylesheet.WRITETEXT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'); LosStylesheet.WRITETEXT('<xsl:output method="xml" encoding="UTF-8" />'); LosStylesheet.WRITETEXT('<xsl:template match="/">'); LosStylesheet.WRITETEXT('<xsl:copy>'); LosStylesheet.WRITETEXT('<xsl:apply-templates />'); LosStylesheet.WRITETEXT('</xsl:copy>'); LosStylesheet.WRITETEXT('</xsl:template>'); LosStylesheet.WRITETEXT('<xsl:template match="*">'); LosStylesheet.WRITETEXT('<xsl:element name="{local-name()}">'); LosStylesheet.WRITETEXT('<xsl:apply-templates select="@* | node()" />'); LosStylesheet.WRITETEXT('</xsl:element>'); LosStylesheet.WRITETEXT('</xsl:template>'); LosStylesheet.WRITETEXT('<xsl:template match="@*">'); LosStylesheet.WRITETEXT('<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>'); LosStylesheet.WRITETEXT('</xsl:template>'); LosStylesheet.WRITETEXT('<xsl:template match="text() | processing-instruction() | comment()">'); LosStylesheet.WRITETEXT('<xsl:copy />'); LosStylesheet.WRITETEXT('</xsl:template>'); LosStylesheet.WRITETEXT('</xsl:stylesheet>'); IF ISCLEAR(LxmlStylesheet) THEN BEGIN CREATE(LxmlStylesheet); END; LxmlStylesheet.load(LisStylesheet); IF ISCLEAR(LxmlToDoc) THEN BEGIN CREATE(LxmlToDoc); END; vPxmlDoc.transformNodeToObject(LxmlStylesheet,LxmlToDoc); LtFilePath := GcuRxCompatible.GetTempFileNamePathOnClient('xml'); LxmlToDoc.save(LtFilePath); CLEAR(LxmlToDoc); CLEAR(LxmlStylesheet); CLEAR(vPxmlDoc); LfXml.OPEN(LtFilePath); LfXml.CREATEINSTREAM(LisStream); CREATE(vPxmlDoc); vPxmlDoc.load(LisStream); LfXml.CLOSE; CLEAR(LfXml); END;
0 -
IMO best way to find values in a normal sized xml file is using xpath. Have a look here for a primer on xpath:
http://www.w3schools.com/xpath/xpath_syntax.asp
Hope this helps
Thomas0
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