-
Update XML
I want to remove encoding="UTF-8" from the line: <?xml version="1.0" encoding="UTF-8"?> in an xml file using C#.
I have seen fuctions to update other elelments but not this, can anyone please help....
I want to update an existing xml file with element: <?xml version="1.0" encoding="UTF-8"?> to <?xml version="1.0"?>.
Thanks!
-
Re: Update XML
Maybe this will do the trick:
Code:
// Load document.
XmlDocument pDoc = new XmlDocument();
pDoc.Load("input.xml");
// Get first node (and check if it is a xml declaration).
XmlDeclaration pDecl = pDoc.FirstChild as XmlDeclaration;
if (pDecl == null)
{
// No xml declaration exists, create one.
pDecl = pDoc.CreateXmlDeclaration("1.0", null, null);
pDoc.InsertBefore(pDecl, pDoc.FirstChild);
}
else
{
// Modify the one we got.
pDecl.Encoding = null;
}
// Save document.
pDoc.Save("output.xml");
- petter
-
Re: Update XML
May you win a million dollar lottery!
Thanks.