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)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.
Syed Haris Shah
9
Mea_
4
Martin Dráb
2
Most Valuable Professional