Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCII character reading issue: Euro symbol coming empty

How can i read € from xml file to java

gives me an error. I want € to be printed

org.xml.sax.SAXParseException; systemId: file:/C:/Users/stikkoo/Desktop/product.xml; lineNumber: 9; columnNumber: 18; The character reference must end with the ';' delimiter.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)

My XML snippet:

<?xml version="1.0" encoding="UTF-8"?>
<company>
    <staff id="1001">
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </staff>
    <staff id="&#128;">
        <firstname>low</firstname>
        <lastname>yin fong</lastname>
        <nickname>fong fong</nickname>
        <salary>200000</salary>
    </staff>
</company>
like image 700
shreya Avatar asked Dec 21 '25 09:12

shreya


2 Answers

First of all, € is not a valid ASCII character. Real ASCII is a 7 bit character set which predates the invention of the € symbol by 30+ years.

Next, € is not present in LATIN-1 (ISO/IEC 8859-1) either. If you need € in an 8-bit ISO/IEC 8859 character set, you need to use ISO-8859-15. The code is 0xA4 or 164 decimal.

In Unicode, the code point for € is U+20AC. That can be written in XML using hexadecimal character entity syntax; &#x20AC;.

Note:

  • The hexadecimal digits are case insensitive.
  • You could also use decimal character entity syntax; &#8364;, but I prefer the hexadecimal form because it better aligns with the Unicode code charts.

Alternatively, you can use the XML / HTML named character entity &euro; ... assuming that your XML parser understands it.


Finally, since you have specified UTF-8 as the encoding for your XML document, you should be able to paste a literal € character into the document ... assuming that you are editing it with a UTF-8 aware editor. (But that has disadvantages too ...)


(There are restrictions on the characters you can use in an XML id, but the € character is allowed.)


For the record, the &#128; character entity that you are trying to use in your document actually refers to a non-printing C1 control character.

like image 199
Stephen C Avatar answered Dec 23 '25 22:12

Stephen C


Hi Shreya!

I think you might have the wrong hexadecimal character for your version of xml. Try &#x20AC; or &#8364;. The following link has a huge wall of text describing basically your exact question!

Link to solve all your problems :)

Good luck with it!

Jesper

like image 36
Jesper Vernooij Avatar answered Dec 23 '25 21:12

Jesper Vernooij



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!