|
-
March 6th, 2006, 04:52 PM
#1
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!
-
March 6th, 2006, 05:43 PM
#2
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
-
March 7th, 2006, 10:06 AM
#3
Re: Update XML
May you win a million dollar lottery!
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|