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. Pound sign in XML

Pound sign in XML

Scheduled Pinned Locked Moved C#
questionxml
18 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.
  • R RugbyLeague

    Hmm, the issues I am having are in an attribute and I am using XDocument rather than XmlDocument. It's interesting yours works though

    R Offline
    R Offline
    Reiss
    wrote on last edited by
    #8

    Sorry misread the XDocument bit, just added this to my original stub and it still works though

    XmlAttribute elem = doc.CreateAttribute("PoundAttribute");
    elem.Value = "£";

    node.Attributes.Append(elem);

    to give

    £

    R 1 Reply Last reply
    0
    • R Reiss

      Sorry misread the XDocument bit, just added this to my original stub and it still works though

      XmlAttribute elem = doc.CreateAttribute("PoundAttribute");
      elem.Value = "£";

      node.Attributes.Append(elem);

      to give

      £

      R Offline
      R Offline
      RugbyLeague
      wrote on last edited by
      #9

      Thanks. Time to scrap XDocument then :)

      R 1 Reply Last reply
      0
      • R RugbyLeague

        Thanks. Time to scrap XDocument then :)

        R Offline
        R Offline
        Reiss
        wrote on last edited by
        #10

        Here you go

        XDocument doc = new XDocument();

        XElement node = new XElement("PoundTest", "");

        XAttribute attrib = new XAttribute("PoundAttribute", "£");

        node.Add(attrib);

        doc.Add(node);

        doc.Save(@"c:\dummy.xml");

        which gives

        R 1 Reply Last reply
        0
        • R Reiss

          Here you go

          XDocument doc = new XDocument();

          XElement node = new XElement("PoundTest", "");

          XAttribute attrib = new XAttribute("PoundAttribute", "£");

          node.Add(attrib);

          doc.Add(node);

          doc.Save(@"c:\dummy.xml");

          which gives

          R Offline
          R Offline
          RugbyLeague
          wrote on last edited by
          #11

          That works for me too. Curiouser and curiouser. Thanks for your help

          R 1 Reply Last reply
          0
          • R RugbyLeague

            I am using XDocument to build XML and writing it out using the Save method - I am having all hell on trying to get it to output a pound (£) sign. I have tried different encodings, tried using XmlWriter etc but nothing seems to work. I have spent all morning reading articles (mainly others asking the same question with not really anything in the way of a reply which works) so how do I get a pound sign into XML? Currently the easiest option appears to be contacting the treasury and asking them to move to the dollar.

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #12

            It's high-bit so you need to encode it, but the XDocument should do that for you (and Reiss's answer would seem to indicate that that is already the case). The named entity is £ but that only applies in HTML, in XML you would have to use £ or set the declared document encoding to ISO-8859-1 (if there are no 2-bit characters) or UTF-8 (encoding the high bit characters appropriately) in the XML header.

            1 Reply Last reply
            0
            • R RugbyLeague

              That works for me too. Curiouser and curiouser. Thanks for your help

              R Offline
              R Offline
              Reiss
              wrote on last edited by
              #13

              Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds :-D

              R 2 Replies Last reply
              0
              • R Reiss

                Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds :-D

                R Offline
                R Offline
                RugbyLeague
                wrote on last edited by
                #14

                Party central is Leeds although it's a long time since I used to haunt the Phono and the Warehouse

                1 Reply Last reply
                0
                • R Reiss

                  Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds :-D

                  R Offline
                  R Offline
                  RugbyLeague
                  wrote on last edited by
                  #15

                  You helped to fix it. You showed the problem wasn't in XML but in the StreamReader I am using to read the data I build into XML - you have to set Encoding on the StreamReader to Encoding.Default - apparently the default isn't Encoding.Default - Bah!!!

                  B 1 Reply Last reply
                  0
                  • R RugbyLeague

                    You helped to fix it. You showed the problem wasn't in XML but in the StreamReader I am using to read the data I build into XML - you have to set Encoding on the StreamReader to Encoding.Default - apparently the default isn't Encoding.Default - Bah!!!

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #16

                    Haha yeah I've tripped over this one a few times. The default is UTF8, I believe. Took me a while to work out that to read a Windows-ANSI file (what most of us actually have on our disks) you have to set it to Default explicitly.

                    R 1 Reply Last reply
                    0
                    • B BobJanova

                      Haha yeah I've tripped over this one a few times. The default is UTF8, I believe. Took me a while to work out that to read a Windows-ANSI file (what most of us actually have on our disks) you have to set it to Default explicitly.

                      R Offline
                      R Offline
                      RugbyLeague
                      wrote on last edited by
                      #17

                      The default it provides isn't default enough apparently :wtf:

                      1 Reply Last reply
                      0
                      • R RugbyLeague

                        I am using XDocument to build XML and writing it out using the Save method - I am having all hell on trying to get it to output a pound (£) sign. I have tried different encodings, tried using XmlWriter etc but nothing seems to work. I have spent all morning reading articles (mainly others asking the same question with not really anything in the way of a reply which works) so how do I get a pound sign into XML? Currently the easiest option appears to be contacting the treasury and asking them to move to the dollar.

                        E Offline
                        E Offline
                        Ennis Ray Lynch Jr
                        wrote on last edited by
                        #18

                        It took Google years to fix it, finally, (as of this week, they did)

                        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                        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