Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying XML namespace

Status
Not open for further replies.

RickBeddoe

Programmer
Nov 18, 2008
32
US
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top