Hi I written some x++ code to export a xml file but I bumped into a small problem my root node have 3 attributes and I add them like this. XMLDocOR = new XMLDocument(); interchange = XMLDocOR.createElement("Interchange"); XMLDocOR.appendChild(Interchange); att1 = XMLDocOR.createAttribute("xmlns"); att1.nodeValue("http://...Omitted..."); interchange.attributes().setNamedItem(att1); att2 = XMLDocOR.createAttribute("xmlns:xsi"); att2.nodeValue("http://...omitted..."); interchange.attributes().setNamedItem(att2); att3 = XMLDocOR.createAttribute("xsi:noNamespaceSchemaLocation"); att3.nodeValue("EAN_Order_Response_Interchange_v1p11.xsd"); interchange.attributes().setNamedItem(att3); when I then want to add a new Node as a child to "Interchange" I add this code envelope = XMLDocOR.createElement("Envelope"); interchange.appendChild(Envelope); Now when I run this the exported file will look like this: <?xml version="1.0" encoding="ISO-8859-1" ?> - <Interchange xmlns=".." xmlns:xsi=".." xsi:noNamespaceSchemaLocation=".."> <Envelope xmlns="" /> </Interchange> Any idea why my "Envelope" inherits the first xmlns"" attribute? appending another child to Interchange will give it the same attribute appending a child to "envelope" will not give the new child a attribute. How do I add children to Interchange w/o getting the xmlns="" attribute? (As this is proberly more something to do with xml than axapta I will try and ask here hope anyone can help me, for now I got a workaround by writing Xmlns insted of xmlns then it wont give all child nodes a empty namespace attribute)
byggemandBob wrote: > Hi I written some x++ code to export a xml file but I bumped into a small > problem > my root node have 3 attributes and I add them like this. > > XMLDocOR = new XMLDocument(); > > interchange = XMLDocOR.createElement("Interchange"); > XMLDocOR.appendChild(Interchange); > att1 = XMLDocOR.createAttribute("xmlns"); > att1.nodeValue("http://...Omitted..."); If you want to create an element in a certain namespace then you need to use a namespace aware creation method. I am not sure which DOM implementation you use with x++, if that is MSXML then you need to use interchange = XMLDocOR.createNode(1, "Interchange", "http://example.com/foo") where http://example.com/foo is the namespace URI. You need to take that approach for all elements to be created in that namespace so if you want to create any child elements then you need to use the same approach e.g. bar = XMLDocOR.createNode(1, "bar", "http://example.com/foo") interchange.appendChild(bar) If you are using the .NET DOM implementation then you don't need to use createNode, instead then there is a namespace aware overload of createElement e.g. interchange = XMLDocOR.createElement("Interchange", "http://example.com/foo") bar = XMLDocOR.createElement("bar", "http://example.com/foo") interchange.appendChild(bar) There is no need to create xmlns attribute. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/