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. Visual Basic
  4. Strip out invalid characters from xml files [modified]

Strip out invalid characters from xml files [modified]

Scheduled Pinned Locked Moved Visual Basic
questionxmlhelp
4 Posts 3 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.
  • I Offline
    I Offline
    Icharus
    wrote on last edited by
    #1

    Can someone help me with the following: 1- I have xml text data that i need to take out invalid characters from. 2- this data contains extraneous characters that i need removed in order to use xmlDocument.LoadXml(str) 3- when this characters are in the str variable i get an XmlException that indicates that there's an invalid character with hex value of 0x0B. 4- how can i remove that character from the string prior to loading it in with xmlDocument.LoadXml(str)? 5- i am using VS2005 Your help is greatly appreciated....:confused: -- modified at 23:11 Thursday 17th August, 2006

    C G I 3 Replies Last reply
    0
    • I Icharus

      Can someone help me with the following: 1- I have xml text data that i need to take out invalid characters from. 2- this data contains extraneous characters that i need removed in order to use xmlDocument.LoadXml(str) 3- when this characters are in the str variable i get an XmlException that indicates that there's an invalid character with hex value of 0x0B. 4- how can i remove that character from the string prior to loading it in with xmlDocument.LoadXml(str)? 5- i am using VS2005 Your help is greatly appreciated....:confused: -- modified at 23:11 Thursday 17th August, 2006

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The string class has a replace method, you would generally call that to remove anything you didn't want in there.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • I Icharus

        Can someone help me with the following: 1- I have xml text data that i need to take out invalid characters from. 2- this data contains extraneous characters that i need removed in order to use xmlDocument.LoadXml(str) 3- when this characters are in the str variable i get an XmlException that indicates that there's an invalid character with hex value of 0x0B. 4- how can i remove that character from the string prior to loading it in with xmlDocument.LoadXml(str)? 5- i am using VS2005 Your help is greatly appreciated....:confused: -- modified at 23:11 Thursday 17th August, 2006

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        1- I see. 2- I see. 3- I see. 4- You can use the Replace method of the string class. 5- Good for you.

        --- b { font-weight: normal; }

        1 Reply Last reply
        0
        • I Icharus

          Can someone help me with the following: 1- I have xml text data that i need to take out invalid characters from. 2- this data contains extraneous characters that i need removed in order to use xmlDocument.LoadXml(str) 3- when this characters are in the str variable i get an XmlException that indicates that there's an invalid character with hex value of 0x0B. 4- how can i remove that character from the string prior to loading it in with xmlDocument.LoadXml(str)? 5- i am using VS2005 Your help is greatly appreciated....:confused: -- modified at 23:11 Thursday 17th August, 2006

          I Offline
          I Offline
          Icharus
          wrote on last edited by
          #4

          Thanks to Christian and Guffa. Below is the solution I was able to come up with...

          Public Structure HexReplacement
          Public HexCharacter As Char
          Public Replacement As String
          End Structure

          Public Shared Function ConvertHexToChar(ByVal hexValue As String) As Char
          Dim convertedChar As Char = Nothing
          Try
          convertedChar = Chr(Int32.Parse(hexValue, Globalization.NumberStyles.HexNumber))
          Catch ex As FormatException
          ' Error handling here....
          Catch ex As ArgumentException
          ' Error handling here....
          End Try
          Return convertedChar
          End Function

          Public Function CleanOutHexValues(ByVal dirtyString As String, ByVal hexReplacements As HexReplacement()) As String
          Dim cleanString As String = dirtyString
          For Each hr As HexReplacement In hexReplacements
          cleanString = cleanString.Replace(hr.HexCharacter, hr.Replacement)
          Next
          Return cleanString
          End Function

          Public Sub TestHexCharCleanUp()
          Dim hr(1) As HexReplacement
          hr(0).HexCharacter = ConvertHexToChar("0b") ' "0b" = or single space.
          hr(0).Replacement = ""
          Dim dirtyString As String = "Testing the removal of "
          MsgBox(CleanOutHexValues(dirtyString, hr))
          End Sub

          Comments will be greatly appreciated. :)

          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