I have next xml file
<xml name="Places">
<data>
<row Code="1" Name="#X1.A&B(City)" />
</data>
</xml>
And after I'm executing unmarshal I'm getting exception The reference to entity "B" must end with the ';' delimiter
because of ampersand(&) inside Name attribute.
JAXBContext jaxbContext = JAXBContext.newInstance(Root.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File xml = new File("test2.xml");
Object obj = unmarshaller.unmarshal(xml);
How can I escape those characters?
I've already tried to add CharacterEscapeHandler but it's not working for Unmarshaller
private static class EscapeHandler implements CharacterEscapeHandler {
@Override
public void escape(char[] buf, int start, int len, boolean isAttValue,
Writer out) throws IOException {
...
}
}
unmarshaller.setProperty("com.sun.xml.bind.marshaller.CharacterEscapeHandler",
new EscapeHandler());
And I'm getting javax.xml.bind.PropertyException: name: com.sun.xml.bind.marshaller.CharacterEscapeHandler