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 ????
:?
0
Comments
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thanks
Please post your code here, I'll try to help.
Thomas
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;
Thanks
For the namespaces-problem I have created a function called "AddElement2" I call the AddElement2 function as follows The Element "SOAP-ENV:Body" will be created this way. Don't forget to declare the prefixed namespace in advance using
Hope this helps
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.
Btw, this is a working sample, Function AddElement2 is described in my earlier post.
Hope this helps
Thomas
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.
Thanks
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 space
Good luck
Thomas
Regards,
Giovanni