Search code examples
javaxmldomxml-parsingw3c

Reading special Charanters in XML org.w3c.dom


I´m reading a XML with characters like "ñ". When i use

...
Node c = nodeList.item( j);
c.getFirstChild().getNodeValue();
...

for to read this

<ID>1Ññ</ID>

I get:

1Ññ

Any idea?

The xml file starts with the following line

<?xml version="1.0" encoding="ISO-8859-1"?>

Solution

  • You have a problem with your character encoding.

    The character sequence Ññ clearly shows that there are UTF-8 characters that are decoded in any other character encoding (presumbly ISO-8859-1).

    Please check your complete application that the encodings are correct.

    Start with the method parse() in the DocumentBuilder and use the method that uses a InputSource and create the InputSource with a Reader that has the correct encoding (ISO-8859-1 in you case).