Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2006

Tip: Looking for answers? Try searching our database.

replace invalid xml characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John A Grandy - 19 Apr 2006 23:52 GMT
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" ?
Mr Flibble - 20 Apr 2006 10:38 GMT
> 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.
Martin Honnen - 20 Apr 2006 13:45 GMT
> 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/frlr
fSystemXmlXmlTextWriterMethodsTopic.asp
>
Xml(Text)Writer provides like WriteBase64 or WriteBinHex do what you need.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.