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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Special characters in XML properties

Special characters in XML properties

Scheduled Pinned Locked Moved C#
xmlhelpquestion
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.
  • Y Offline
    Y Offline
    yonidebest
    wrote on last edited by
    #1

    I have an XML with non-english characters in the property name. My XML is something like this: 10,000,000 Now, instead of "New York", I have "ניו יורק", which is NY in Hebrew. Unfortunately, I cannot change this, and the problem is that the code won't recognize it. The code: XmlDocument doc = new XmlDocument(); doc.Load("C:\pop.xml"); XmlNode xml = doc.DocumentElement; string pop = xml.SelectSingleNode("/file/city[@name='" + cityName + "']/pop").InnerText; Where cityName is New York in Hebrew. I tried changing the NY in all places to English - and the code worked, so I guess it's the Hebrew that is doing the problem. Any idea how I can resolve this? Thanks, Yoni

    M 1 Reply Last reply
    0
    • Y yonidebest

      I have an XML with non-english characters in the property name. My XML is something like this: 10,000,000 Now, instead of "New York", I have "ניו יורק", which is NY in Hebrew. Unfortunately, I cannot change this, and the problem is that the code won't recognize it. The code: XmlDocument doc = new XmlDocument(); doc.Load("C:\pop.xml"); XmlNode xml = doc.DocumentElement; string pop = xml.SelectSingleNode("/file/city[@name='" + cityName + "']/pop").InnerText; Where cityName is New York in Hebrew. I tried changing the NY in all places to English - and the code worked, so I guess it's the Hebrew that is doing the problem. Any idea how I can resolve this? Thanks, Yoni

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Fix the encoding attribute in the <?xml?> tag so it matches the actual encoding of the XML.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      Y 1 Reply Last reply
      0
      • M Michael Dunn

        Fix the encoding attribute in the <?xml?> tag so it matches the actual encoding of the XML.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        Y Offline
        Y Offline
        yonidebest
        wrote on last edited by
        #3

        Thanks. For some reason, the ISO-8859-1 wasn't enough, so I changed it to ISO-8859-8. Yoni

        L 1 Reply Last reply
        0
        • Y yonidebest

          Thanks. For some reason, the ISO-8859-1 wasn't enough, so I changed it to ISO-8859-8. Yoni

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

          Use UTF-8 (default of XML). Everything but Unicode (the encodings UTF8, UTF16, or UTF32) is depricated and only supported to allow loading data from legacy programs.

          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