Pound sign in XML
-
I had a dig around and couldn't find anything in particular for £ signs - so I created this quick stub and it is working as expected for me
XmlDocument doc = new XmlDocument();
XmlNode node = doc.CreateNode(XmlNodeType.Element, "PoundTest", "Dummy");
node.InnerXml = "£";doc.AppendChild(node);
doc.Save(@"c:\dummy.xml");
which outputs
£
Hmm, the issues I am having are in an attribute and I am using XDocument rather than XmlDocument. It's interesting yours works though
-
Hmm, the issues I am having are in an attribute and I am using XDocument rather than XmlDocument. It's interesting yours works though
-
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
£
Thanks. Time to scrap XDocument then :)
-
Thanks. Time to scrap XDocument then :)
-
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
That works for me too. Curiouser and curiouser. Thanks for your help
-
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.
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.
-
That works for me too. Curiouser and curiouser. Thanks for your help
-
Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds :-D
Party central is Leeds although it's a long time since I used to haunt the Phono and the Warehouse
-
Glad I could help - I lived just outside Garforth for 8 years and had many a good night out in Leeds :-D
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!!!
-
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!!!
-
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.
The default it provides isn't default enough apparently :wtf:
-
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.
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