RickBeddoe
Programmer
Hello
I have an XML document in which I need to change a namespace.
<root
xmlns:abc=>
Within the XML file I have elements within the abc namespace:
<abc:myElement>123456</abc:myElement>
I use the following code to modify the namespace:
XmlDocument myXmlDoc = new XmlDocument;
myXmlDoc.Load("myxml.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(XmlDoc.NameTable);
XmlNode rootXmlNode = myXmlDoc.SelectSingleNode("/*[local-name()='root']",nsmgr);
XmlNode abcNode = rootXmlNode.Attributes.GetNamedItem("xmlns:abc");
abcNode.Attributes.SetNamedItem(abcNode).Value = "
So, hopefully you can see from this that I'm changing the namespace value from to
Now, when I save the file:
myXmlDoc.Save(xmlFilename);
an attribute for the namespace gets added to the element:
<abc:myElement xmlns:abc="
This is causing a big problem as the namespace is already defined as in the root element.
I've tried using XmlWriter but the results are the same.
I have an XML document in which I need to change a namespace.
<root
xmlns:abc=>
Within the XML file I have elements within the abc namespace:
<abc:myElement>123456</abc:myElement>
I use the following code to modify the namespace:
XmlDocument myXmlDoc = new XmlDocument;
myXmlDoc.Load("myxml.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(XmlDoc.NameTable);
XmlNode rootXmlNode = myXmlDoc.SelectSingleNode("/*[local-name()='root']",nsmgr);
XmlNode abcNode = rootXmlNode.Attributes.GetNamedItem("xmlns:abc");
abcNode.Attributes.SetNamedItem(abcNode).Value = "
So, hopefully you can see from this that I'm changing the namespace value from to
Now, when I save the file:
myXmlDoc.Save(xmlFilename);
an attribute for the namespace gets added to the element:
<abc:myElement xmlns:abc="
This is causing a big problem as the namespace is already defined as in the root element.
I've tried using XmlWriter but the results are the same.