Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. utility/library to clean-up xml-strings (&amp, etc)

utility/library to clean-up xml-strings (&amp, etc)

Scheduled Pinned Locked Moved XML / XSL
toolsxml
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ohadp
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • O ohadp

      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

      J Offline
      J Offline
      Jim Taylor
      wrote on last edited by
      #2

      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("&", "&amp;") s = s.Replace(">", "&gt;") s = s.Replace("<", "&lt;") s = s.Replace(ControlChars.Quote, "&quot;") 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

      O 1 Reply Last reply
      0
      • J Jim Taylor

        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("&", "&amp;") s = s.Replace(">", "&gt;") s = s.Replace("<", "&lt;") s = s.Replace(ControlChars.Quote, "&quot;") 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

        O Offline
        O Offline
        ohadp
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • O ohadp

          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

          J Offline
          J Offline
          Jim Taylor
          wrote on last edited by
          #4

          Just to confirm the characters: & < > " ' ControlChars.Quote is the equivalent for C's \" Jim

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups