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

Notifications

Announcements

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 351
 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)
  • Verified answer
    Martin Dráb Profile Picture
    238,522 Most Valuable Professional on at
    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.
  • PriyaDutta Profile Picture
    351 on at
    Hi Martin,
     
    I do not want any namespace for the CstmrCdtTrfInitn node.
    It should come as 
     
  • Martin Dráb Profile Picture
    238,522 Most Valuable Professional on at
    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
    351 on at
    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
    238,522 Most Valuable Professional on at
    I'm glad I was able to help. Now, please don't forget to verify the answer.

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 438 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 358 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans