xml namespace problem

Blackcat
Member Posts: 28
I have a problem adding a namespace (xmlns) to a tag in my XML DOM Document.
Let my try to explain. Before I add the namespace, all my tags are looking fine and dandy:
<tag1>...
<tag2>...
<tag3>...
But as soon as I add the namespace to tag1, all its child tags automatically get the empty namespace xmlns="" added to them, so now my XML DOM Document looks like this:
<tag1 xmlns="validURL">...
<tag2 xmlns="">...
<tag3 xmlns="">...
And i want it to look like this
<tag1 xmlns="validURL">...
<tag2 >...
<tag3 >...
Can anyone please help me ????
:?
Let my try to explain. Before I add the namespace, all my tags are looking fine and dandy:
<tag1>...
<tag2>...
<tag3>...
But as soon as I add the namespace to tag1, all its child tags automatically get the empty namespace xmlns="" added to them, so now my XML DOM Document looks like this:
<tag1 xmlns="validURL">...
<tag2 xmlns="">...
<tag3 xmlns="">...
And i want it to look like this
<tag1 xmlns="validURL">...
<tag2 >...
<tag3 >...
Can anyone please help me ????
:?
0
Comments
-
add it as a attribute element type to the xml port.0
-
I have the same problem on NAV 3.70 which is not working with XML ports. I writed some code to generate an XML file but I'm facing the same issue. Did you have a solution for this?
Thanks0 -
This is a piece of my code. I have problem when using the AddAttribute function (codeunit 6224). On all tags of same level it comes with xmlns="" as you described in your request.
XMLDocOut.loadXML := '<AuditFile/>';
XMLCurrNode := XMLDocOut.documentElement;
XMLFirstNode := XMLCurrNode;
DocNameSpace := '';
WITH XMLDOMManagement DO BEGIN
XMLDOMManagement.SetNormalCase;
IF AddAttribute(XMLCurrNode,'xmlns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN
EXIT;
IF AddAttribute(XMLCurrNode,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance') >0 THEN
EXIT;
IF AddElement(XMLCurrNode,'Header','',DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
//New child
XMLCurrNode := XMLNewChild;
IF AddAttribute(XMLCurrNode,'xmlns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN
EXIT;
IF XMLDOMManagement.AddElement(XMLCurrNode,'AuditFileVersion',VersionNo,DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
IF AddElement(XMLCurrNode,'CompanyID',CompanyInfo."Registration Authority" + '/' + CompanyInfo."Registration No."
,DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
IF AddElement(XMLCurrNode,'TaxRegistrationNumber',CompanyInfo."VAT Registration No.",DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
IF AddElement(XMLCurrNode,'TaxAccountingBasis',TaxAccountBasisTxt,DocNameSpace,XMLNewChild) > 0 THEN
EXIT;
Thanks0 -
I had also problems using functions from cu6224.
For the namespaces-problem I have created a function called "AddElement2"AddElement2(VAR XMLNode : Automation "'Microsoft XML, v6.0'.DOMDocument60";NodeName : Text[250];NodeText : Text[250];VAR CreatedXMLNode // adapted from Codeunit 6224 NewChildNode := XMLNode.ownerDocument.createElement(NodeName); IF NodeText <> '' THEN NewChildNode.text := NodeText; XMLNode.appendChild(NewChildNode); CreatedXMLNode := NewChildNode;
I call the AddElement2 function as followsAddElement2(CurrNode,'SOAP-ENV:Body','',NewChild);
The Element "SOAP-ENV:Body" will be created this way. Don't forget to declare the prefixed namespace in advance usingxmlMgt.AddAttribute(CurrNode,'xmlns:SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/');
Hope this helps
Thomas0 -
Hi Thomas,
Thanks for your help. I tried it but it doesn't help or I make something wrong. I always have xmlns="" in the file.
<?xml version="1.0" encoding="windows-1252" ?>
<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.00_01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.00_01">
<AuditFileVersion xmlns="">1.00_01</AuditFileVersion>
<CompanyID xmlns="">/HRG/RCG </CompanyID>
<TaxRegistrationNumber xmlns="">123456789</TaxRegistrationNumber>
<TaxAccountingBasis xmlns="">Integrado - Contabilidade e Facturação</TaxAccountingBasis>
<CompanyName xmlns="">CRONUS PT</CompanyName>
<CompanyAddress xmlns="">
<AddressDetail>Louisa street</AddressDetail>
<City>Bxl</City>
<PostalCode>B-1000</PostalCode>
<Country>Belgium</Country>
</CompanyAddress>
<FiscalYear xmlns="">2009</FiscalYear>
<StartDate xmlns="">2008-07-01</StartDate>
<EndDate xmlns="">2009-06-30</EndDate>
<CurrencyCode xmlns="">EUR</CurrencyCode>
<DateCreated xmlns="">2008-11-04</DateCreated>
<ProductID xmlns="">Microsoft Business Solutions-Navision/Microsoft</ProductID>
<ProductVersion xmlns="">PT 3.70</ProductVersion>
</Header>
<MasterFiles xmlns="">
Thanks.0 -
Strange. Can you post your new code here?
Btw, this is a working sample, Function AddElement2 is described in my earlier post.CREATE(XMLDoc); xmlMgt.SetNormalCase; xmlProcessingInst:=XMLDoc.createProcessingInstruction('xml','version="1.0" encoding="utf-8"'); CurrNode := XMLDoc.appendChild(xmlProcessingInst); CurrNode := XMLDoc.createElement('SOAP-ENV:Envelope'); CurrNode := XMLDoc.appendChild(CurrNode); xmlMgt.AddAttribute(CurrNode,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance'); xmlMgt.AddAttribute(CurrNode,'xmlns:ns001','http://www.abc.com'); xmlMgt.AddAttribute(CurrNode,'xmlns:SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/'); AddElement2(CurrNode,'SOAP-ENV:Body','',NewChild); CurrNode := NewChild; AddElement2(CurrNode,'ns001:Add','',NewChild); CurrNode := NewChild; AddElement2(CurrNode,'ns001:dbl1',FORMAT(Value1),NewChild); AddElement2(CurrNode,'ns001:dbl2',FORMAT(Value2),NewChild); IF SaveRequest THEN XMLDoc.save('c:\temp\webserviceRequest.xml'); { <?xml version="1.0" encoding="utf-8" ?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns001="http://www.abc.com" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <ns001:Add> <ns001:dbl1>7</ns001:dbl1> <ns001:dbl2>8</ns001:dbl2> </ns001:Add> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Hope this helps
Thomas0 -
XMLDocOut.loadXML := '<AuditFile/>';
XMLCurrNode := XMLDocOut.documentElement;
XMLFirstNode := XMLCurrNode;
DocNameSpace := '';
WITH XMLDOMManagement DO BEGIN
XMLDOMManagement.SetNormalCase;
IF AddAttribute(XMLCurrNode,'xmlns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN
EXIT;
IF AddAttribute(XMLCurrNode,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance') >0 THEN
EXIT;
AddElement2(XMLCurrNode,'Header','',XMLNewChild);
//New child
XMLCurrNode := XMLNewChild;
IF AddAttribute(XMLCurrNode,'xmlns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN
EXIT;
DocNameSpace := '';
AddElement2(XMLCurrNode,'AuditFileVersion',VersionNo,XMLNewChild);
AddElement2 is using the code you sent before.
Thanks0 -
True, didn't kow that
Have a look at this:
http://www.eggheadcafe.com/aspnet_answe ... 671481.asp
It basically says that if the parent node has a namespace, then XMLDOM adds the xmlns="" attribute by default. You can test it if you remove all namespace attributes from the parents.
You have 3 possiblilities:
1) Check with the consumer of your xml-File whether the empty tag is a problem, imho it should not be a problem if the consumer works according to all xml-Rules
2) Declare a kind of default name space and use it for those tags without name spaceIF xmlDOMManagement.AddAttribute(XMLCurrNode,'xmlns:myns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN ..snip // This is not needed anymore for the Header-Node anymore, it's using myns //IF xmlDOMManagement.AddAttribute(XMLCurrNode,'xmlns','urn:OECD:StandardAuditFile-Tax:PT_1.00_01') >0 THEN
Good luck
Thomas0 -
Ok Thanks for your help.
Regards,
Giovanni0
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