web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Extra namespace coming in document node

(1) ShareShare
ReportReport
Posted on by 333
 Hi All,
 
I am trying to generate xml file.
But there is extra namespace coming in CstmrCdtTrfInitn  node.
 
 
 
Expected :
 
 
Please see my code below
 rootNode = xmlDoc.documentElement();


 docNode = xmlDoc.createElement2('Document',"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
 docNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
 xmlDoc.appendChild(docNode);

 XmlNode CstmrNode;

 CstmrNode = xmlDoc.createElement('CstmrCdtTrfInitn');
 docNode.appendChild(CstmrNode);                        //todo
 xmlElement = xmlDoc.createElement('GrpHdr');
 NodeName =  CstmrNode.appendChild(xmlElement);
Please help.
 
Thanks,
Priya
I have the same question (0)
  • Martin Dráb Profile Picture
    235,999 Most Valuable Professional on at
    Extra namespace coming in document node
    I'm glad I was able to help. Now, please don't forget to verify the answer.
  • PriyaDutta Profile Picture
    333 on at
    Extra namespace coming in document node
    Hi Martin,
     
    Thanks for your suggestion. Finally got what was wrong. I added same namespace to all the child nodes, now the extra xmlns="" is not showing in any node.
     
    For reference :
     
     xmlDoc = XMLDocument::newBlank();
     
     // Create first line containing version info
     rootNode = xmlDoc.documentElement();
    
     docNode = xmlDoc.createElement2('Document',"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
     docNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
     xmlDoc.appendChild(docNode);
    
     CstmrNode = xmlDoc.createElement2('CstmrCdtTrfInitn',"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
     docNode.appendChild(CstmrNode);
     
     xmlElement = xmlDoc.createElement2('GrpHdr',"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
     NodeName =  docNode.appendChild(xmlElement);
     xmlElement = xmlDoc.createElement2('MsgId',"urn:iso:std:iso:20022:tech:xsd:pain.001.001.03");
     NodeMsg = NodeName.appendChild(xmlElement);
     xmlText =xmlDoc.createTextNode(numseq);
     NodeMsg.appendChild(xmlText);
     
     
    Thanks,
    Priya
  • Martin Dráb Profile Picture
    235,999 Most Valuable Professional on at
    Extra namespace coming in document node
    Yes, I know you don't want any xmlns attribute there, but it doesn't mean you can ignore namespaces.

    To achieve the result you want, the elements under Document must belong to the same namespace as Document. Your current problem is caused by the fact that the namespace are different; the xmlns="" attribute is added to CstmrCdtTrfInitn because the namespace must be changed from http://www.w3.org/2001/XMLSchema-instance to "". There is no xmlns="" on GrpHdr because it has the same namespace as CstmrCdtTrfInitn (= "").
     
    You may want to learn a bit more XML namespaces before continuing.
  • PriyaDutta Profile Picture
    333 on at
    Extra namespace coming in document node
    Hi Martin,
     
    I do not want any namespace for the CstmrCdtTrfInitn node.
    It should come as 
     
  • Verified answer
    Martin Dráb Profile Picture
    235,999 Most Valuable Professional on at
    Extra namespace coming in document node
    The reason is that you didn't specify the namespace of CstmrCdtTrfInitn, therefore the namespace of CstmrCdtTrfInitn is different than the namespace of its parent node (empty vs. http://www.w3.org/2001/XMLSchema-instance).
     
    You seem to want the same namespace for all nodes, therefore you should do that. You can, for example, use createElement2() instead of createElement(), because createElement2() has a parameter for the namespace URI.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 841 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 753 Super User 2025 Season 2

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 566

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans