XmlDocument doc1 = new XmlDocument(); doc1.Load(filePath1); Document type:
<?xml version="1.0" standalone="yes"?> <DBModel xmlns="http://tempuri.org/DBModel.xsd"> <Persons> <Id>1</Id> <Name>TestName</Name> <SecondName>TestSecName</SecondName> <ThirdName>TestThirdName</ThirdName> <FullName>TestSecName TestName TestThirdName</FullName> </Persons> </DBModel> If you add a node and save:
var asd = doc1.CreateElement("Location"); asd.InnerText = Text; parent.AppendChild(asd); doc1.Save(filePath1.Replace(".xml", "_new.xml")); That will turn out:
<Persons> <Id>1</Id> <Name>TestName</Name> <SecondName>TestSecName</SecondName> <ThirdName>TestThirdName</ThirdName> <FullName>TestSecName TestName TestThirdName</FullName> <Location xmlns="">Text</Location> </Persons> Respectively <Location xmlns=""> /// is not readable.
doc1.CreateElement("Location", "http://tempuri.org/DBModel.xsd")- Sublihimdoc1.CreateElement("Location", doc1.DocumentElement.NamespaceURI), so that the namespace is not explicitly specified - kmv