There are some cases in which one has to deal with non-standard XML serialization. We all know why this can happen, (cough, cough, legacy code) but then we have to make things work anyway. So...say you are reading and writing XML that uses single quotes instead of double quotes to surround attributes (its valid, just non-standard). If you used XmlDocument.Save() to write out the DOM, you then may have been dismayed to see double quotes. So how to make .NET spit out single quotes?
public void WriteSingleQuotedXml(XmlDocument document, string path)
{
using (XmlTextWriter writer =
new XmlTextWriter(path, System.Text.Encoding.Default))
{
//Save using single quotes around attributes, etc
writer.QuoteChar = '\'';
// Write XML data.
document.Save(writer);
}
}
Now that that is out of the way, perhaps you need to get rid of the leading "< ? x m l >", "xmlns:xsi" and "xmlns:xsd" stuff?
0 comments:
Post a Comment