Skip to main content

Notifications

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
  • Martin Dráb Profile Picture
    234,484 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
    234,484 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
    234,484 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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans