John A Grandy wrote:
I know that System.Security.SecurityElement.Escape() will replace invalid
xml chars with valid equivalent ...
But is there another method to accomplish same that is "closer to home" ?
If you want to create XML with .NET then Xml(Text)Writer is the tool and
its methods will do all escaping necessary for you e.g.
XmlTextWriter xmlWriter = new XmlTextWriter(Console.Out);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("root");
xmlWriter.WriteElementString("text", "Kibo & Xibo");
xmlWriter.WriteElementString("comparison", "a < b");
xmlWriter.WriteEndDocument();
xmlWriter.Close();
will write
<root>
<text>Kibo & Xibo</text>
<comparison>a < b</comparison>
</root>
so everything is escaped as necessary.
If that does not help then tell exactly which kind of "invalid"
characters you have or maybe check first whether some of the other methods
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlTextWriterMethodsTopic.asp>
Xml(Text)Writer provides like WriteBase64 or WriteBinHex do what you need.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/