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

Announcements

No record found.

News and Announcements icon
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
    239,029 Most Valuable Professional on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans