I have a xml document with a namespaceURI set for the root element. I want to add new elements with this ns. I wrote this code:
XmlDocument doc=new XmlDocument();
doc.LoadXml("<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"></w:wordDocument>");
XmlElement child=doc.CreateElement("w:body");
doc.DocumentElement.AppendChild(child);
//NamespaceURI remains empty
Assert.AreEqual(child.NamespaceURI,"http://schemas.microsoft.com/office/word/2003/wordml");
Setting the prefix doesn’t effect the namespaceURI. And it serializes
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<body></body>
</w:wordDocument>
Instead of
<w:body></w:body>
what can i do? Thanks for your help.
1 Answer