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 :
Microsoft Dynamics AX (Archived)

Write Xml-file with character " : "

(0) ShareShare
ReportReport
Posted on by 85

Hi,

I try to write an xml-file to a external system and have problem to put the character ":" into a node name.

The xml-file should look like this:


<?xml version="1.0" encoding="utf-8"?>
<imf xmlns="http://www.test.com/imf/3.0"
     xmlns:flowman="http://www.test.com/imf/3.0">
  <head>
    <version>3.0</version>
    <source supplier="Test" application="Test Server"/>
    <time>2012-05-16T08:35:02</time>
  </head>
  <body>
      <attributes>
        <Item:Fullname>TestItem</Item:Fullname>
      </attributes>....
 ....


 My Code is:
    .
    .
    // First row.
    xmlDoc = new XMLDocument();
    root   = xmlDoc.documentElement();
    XMLpi  = xmlDoc.createProcessingInstruction('xml', 'version=\"1.0\" encoding=\"UTF-8\"');
    xmlDoc.appendChild(XMLpi);
   
    // Second row: Have child.
    element = xmlDoc.createElement('imf');
    element.setAttribute('xmlns', "http://www.ifra.com/imf/3.0");
    element.setAttribute('xmlns:flowman', "http://www.flowman.fi/imf/3.0");
    root    = xmlDoc.appendChild(element);
    //Head
    level2Element = xmlDoc.createElement('Head');
    .
    .          
    level3Element = xmlDoc.createElement('Item:Fullname');
    .
    .   

My problem is the node:  

     <Item:Fullname>Test item</Item:Fullname> .

I cant give the node correct node name.
I tried following:

    level3Element = xmlDoc.createElement('Item:Fullname');

but it only write in the xml-file:

    <Fullname>TestItem</Fullname>

I tried different methods under the element Node and didnt find a way to get it right.

Does somebody know how to do this??


Thanks for help.  

Regards: Björn

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    Re: Write Xml-file with character " : "

    What is before ":", i.e. "Item" in your case, represents XML namespace. Normally you would do something like this:

    str namespaceURI = 'http://SomeNamespaceURI';
    //Here you define namespace prefix, element name and namespace URI
    element = xmlDoc.createElement3('Item', 'imf', namespaceURI);
    (...)
    level3Element = xmlDoc.createElement3('Item', 'Fullname', namespaceURI);

    But your "template" XML doesn't contain definition of "Item" namespace, therefore it's invalid.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans