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. C#
  4. XmlReader problem when XML has non foreign special characters [modified]

XmlReader problem when XML has non foreign special characters [modified]

Scheduled Pinned Locked Moved C#
xmlhelptutorialquestion
4 Posts 4 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.
  • A Offline
    A Offline
    Andreas X
    wrote on last edited by
    #1

    Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006

    G E 2 Replies Last reply
    0
    • A Andreas X

      Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006

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

      Specify the encoding when you create the streamreader. Example: StreamReader reader = new StreamReader(fileName, Encoding.GetEncoding("windows-1250"));

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

      L 1 Reply Last reply
      0
      • G Guffa

        Specify the encoding when you create the streamreader. Example: StreamReader reader = new StreamReader(fileName, Encoding.GetEncoding("windows-1250"));

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

        L Offline
        L Offline
        lmoelleb
        wrote on last edited by
        #3

        I recommend fixing the XML document instead of trying to make your program read invalid XML. See for example here[^] The default encoding is UTF-8, if you use anything else you must a) Specify it in the header b) Kill yourself to save the world from yet more ANSI junk. Only exception is if you use another Unicode encoding (UTF-16 for example), but normally this is not needed. :)

        1 Reply Last reply
        0
        • A Andreas X

          Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006

          E Offline
          E Offline
          eggie5
          wrote on last edited by
          #4

          First of all, what is your code, what reader are you using? An xml reader, DOM, SAX, or a text reader? No doc type (header)?? That's actually not valid XML. Is it possible to include it? Short of a Byte order mark, w/o the doc type there is NO way to accurately figure out the encoding of file. If you can't add the doc type to your XML doc, you must specify the encoding in your code. UTF-8 would be a safe guess. -- modified at 3:03 Sunday 6th August, 2006 -- modified at 3:04 Sunday 6th August, 2006

          /\ |_ E X E GG

          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