utility/library to clean-up xml-strings (&amp, etc)
-
I need something that correctly 'cleans' a string that exists in xml by removing all the & and other tags that translate into regular characters... thanks
If you are using .NET and the DOM (or an System.Xml.XmlTextWriter) then this is handled automatically for you. If you are just creating xml by manipulating strings or cutting and pasting then you will need a utility to handle it for you. If this was written in vb.NET the following class would handle it for you.
Public Class XMLUtility Private Sub New() End Sub Public Shared Function ReplaceIllegalXMLChars(ByVal s As String) As String s = s.Replace("&", "&") s = s.Replace(">", ">") s = s.Replace("<", "<") s = s.Replace(ControlChars.Quote, """) s = s.Replace("'", "'") Return s End Function End Class
It would be a simple task to turn it into a simple app to paste a string into a text box click convert and display it in another text box. If you wanted me to knock something up then drop me a line. Another way to do it would be using an html page with javascript to perform the same task in exactly the same manner. Jim -
If you are using .NET and the DOM (or an System.Xml.XmlTextWriter) then this is handled automatically for you. If you are just creating xml by manipulating strings or cutting and pasting then you will need a utility to handle it for you. If this was written in vb.NET the following class would handle it for you.
Public Class XMLUtility Private Sub New() End Sub Public Shared Function ReplaceIllegalXMLChars(ByVal s As String) As String s = s.Replace("&", "&") s = s.Replace(">", ">") s = s.Replace("<", "<") s = s.Replace(ControlChars.Quote, """) s = s.Replace("'", "'") Return s End Function End Class
It would be a simple task to turn it into a simple app to paste a string into a text box click convert and display it in another text box. If you wanted me to knock something up then drop me a line. Another way to do it would be using an html page with javascript to perform the same task in exactly the same manner. JimHi Jim, What I have is C/C++ code that has the XML page contained in a buffer. The best thing for me would be to use a function like the one you described here. Are you positive these are all the special cases I may encounter ? is ControlChars.Quote the equivalent for C's \" ? Thanks
-
Hi Jim, What I have is C/C++ code that has the XML page contained in a buffer. The best thing for me would be to use a function like the one you described here. Are you positive these are all the special cases I may encounter ? is ControlChars.Quote the equivalent for C's \" ? Thanks
Just to confirm the characters: & < > " ' ControlChars.Quote is the equivalent for C's \" Jim