Problem with XML namespaces

Emerik
Member Posts: 50
Hi,
I'm trying to create some XML files from purchase orders. These are to be validated by a workflow system. Thus, the header tag contains references to xml schemas, and the tags inside are appropriately declared with namespace prefixes.
The problem is, that the schemas are not available at creation of the xml file. The xml file is first validated inside the external workflow system. So, the namespace references give sense inside the external workflow system, but does not outside, as in Navision, where the file is created.
I am using the "'Microsoft XML, v.3.0'.DOMDocument" to create the xml file.
There are 2 scenarios (both are bad, the first worse than the second, though)
1. The tags are create with a blank namespace value. Result: The object compiles just fine, but refuses to create the file, exiting with the error:
2. The tags are created with the corresponding namespace reference. Result: The file is created, with all tags filled with namespace references. This means unnecessarily large files, since the reference are already in the header.
Isn't there any way to avoid having to repeat the namespace reference for every tag?
Code example
I'm trying to create some XML files from purchase orders. These are to be validated by a workflow system. Thus, the header tag contains references to xml schemas, and the tags inside are appropriately declared with namespace prefixes.
The problem is, that the schemas are not available at creation of the xml file. The xml file is first validated inside the external workflow system. So, the namespace references give sense inside the external workflow system, but does not outside, as in Navision, where the file is created.
I am using the "'Microsoft XML, v.3.0'.DOMDocument" to create the xml file.
There are 2 scenarios (both are bad, the first worse than the second, though)
1. The tags are create with a blank namespace value. Result: The object compiles just fine, but refuses to create the file, exiting with the error:
This message is for C/AL programmers:
The call to member createNode failed. msxml3.dll returned the following message: Reference to undeclared namespace prefix: 'icc'.
2. The tags are created with the corresponding namespace reference. Result: The file is created, with all tags filled with namespace references. This means unnecessarily large files, since the reference are already in the header.
Isn't there any way to avoid having to repeat the namespace reference for every tag?
Code example
CREATE(XMLPurchaseOrder); // Initialiser DocNameSpace := ''; Prefix := 'icc'; strHeader := '<?xml version="1.0" encoding="UTF-8" ?><PurchaseOrderInformation/>'; XMLPurchaseOrder.loadXML:=strHeader; XMLCurrNode := XMLPurchaseOrder.documentElement; // >> POI WITH XMLDOMManagement DO BEGIN AddAttribute(XMLCurrNode,'xmlns','urn:purchaseorderinformation:200511'); AddAttribute(XMLCurrNode,'xmlns:util','http://www.proceedo.net/xslt/lib/Util'); AddAttribute(XMLCurrNode,'xmlns:ifc','urn:components:financialaccount:200511'); AddAttribute(XMLCurrNode,'xmlns:ibc','urn:components:business:200511'); AddAttribute(XMLCurrNode,'xmlns:icc','urn:components:core:200511'); AddElement(XMLCurrNode,'References','',DocNameSpace,XMLNewChild,Prefix); XMLCurrNode := XMLNewChild; // >> POI/Refs AddElement(XMLCurrNode,'Reference',PurchaseOrder."No.",DocNameSpace,XMLNewChild,Prefix); AddAttribute(XMLNewChild,'scheme','urn:ibistic:order:reference:buyer'); XMLCurrNode := XMLCurrNode.parentNode; // >> POI Prefix := ''; AddElement(XMLCurrNode,'IssueDate',DateToText(PurchaseOrder."Order Date"),DocNameSpace,XMLNewChild,Prefix); AddElement(XMLCurrNode,'Type','Standard',DocNameSpace,XMLNewChild,Prefix); IF PurchaseOrder.Status = PurchaseOrder.Status::Open THEN txtStatus := 'Open' ELSE txtStatus := 'Closed'; AddElement(XMLCurrNode,'Status',txtStatus,DocNameSpace,XMLNewChild,Prefix); AddElement(XMLCurrNode,'LastUpdated',DateTimeToText(CURRENTDATETIME), DocNameSpace,XMLNewChild,Prefix); Prefix := 'icc'; AddElement(XMLCurrNode,'Amount','',DocNameSpace,XMLNewChild,Prefix); AddAttribute(XMLNewChild,'currency',PurchaseOrder."Currency Code"); XMLCurrNode := XMLNewChild; // >> POI/Amount AddElement(XMLCurrNode,'AmountInclusiveTax',FORMAT(PurchaseOrder."Amount Including VAT"),DocNameSpace,XMLNewChild,Prefix); AddElement(XMLCurrNode,'AmountExclusiveTax',FORMAT(PurchaseOrder.Amount),DocNameSpace,XMLNewChild,Prefix); AddElement(XMLCurrNode,'TaxAmount',FORMAT(PurchaseOrder."Amount Including VAT"-PurchaseOrder.Amount), DocNameSpace,XMLNewChild,Prefix); XMLCurrNode := XMLCurrNode.parentNode; // >> POI ... END; XMLPurchaseOrder.save(ExportDir);
0
Comments
-
Is the problem solved?
I have problem like this.
Can you hep me ?0 -
I had the same problem, and found the solution as follows:
The trick is to declare the namespaces with a text constants (to make life easier...), and use the text constant instead of the prefix as last parameter in all Element-function calls where a prefix is used.ProcessingInstruction(XMLDoc,'1.0','utf-8',''); AddElement(XMLDoc,aRootElement,'SSU_WHS_Interface_Data','',''); XMLDoc.appendChild(aRootElement); addAttribute(XMLDoc,aRootElement,'xmlns', __Namespace ); addAttribute(XMLDoc,aRootElement,'xmlns:ssu', __NamespaceSSU ); AddElement(XMLDoc,aSessionInfo,'ssu:SessionInfo','', __NamespaceSSU);
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