471,071 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

replace invalid xml characters

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" ?
Apr 19 '06 #1
2 7982
* 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" ?


I usually use the stream editor "sed" for this type of stuff.
Apr 20 '06 #2


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 &amp; Xibo</text>
<comparison>a &lt; 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/
Apr 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by WindAndWaves | last post: by
14 posts views Thread by Nicolas Bouillon | last post: by
4 posts views Thread by Hardy Wang | last post: by
5 posts views Thread by cj | last post: by
2 posts views Thread by =?iso-8859-1?B?RnJhbiBHYXJj7WE=?= | last post: by
6 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.