Skip to main content

Help to unmarshal UTF-16 xml

1 reply [Last post]
brasta78
Offline
Joined: 2010-12-30
Points: 0

I have SOAP response msg:
<?xml version="1.0" encoding="UTF-16" standalone="yes"?><xmsData client=.....
(< is & l t ;)
Then I try ti unmarshal:

JAXBElement<TXmsData> xmsD = null;
try {
ObjectFactory of = new ObjectFactory();
JAXBContext jc = JAXBContext.newInstance(of.getClass().getPackage().getName());
Unmarshaller u = jc.createUnmarshaller();
StringBuilder xmlStr = new StringBuilder(<?xml version="1.0" encoding="UTF-16" standalone="yes><xmsData client=....);
xmsD = (JAXBElement<TXmsData>)u.unmarshal(new StreamSource(new StringReader(xmlStr.toString())));
TXmsData data = xmsD.getValue();
System.out.println("out: " + data.getUser().getUserId());
} catch (JAXBException ex) {

also I tryed with :

ByteArrayInputStream input = new ByteArrayInputStream(reader.toString().getBytes("UTF-16"));
JAXBContext jc = JAXBContext.newInstance(of.getClass().getPackage().getName());
Unmarshaller u = jc.createUnmarshaller();
xmsD = (JAXBElement<TXmsData>) u.unmarshal(input);

but always get this error:
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: Content is not allowed in prolog.]

How can I unmarshal this xml? shoul I do replaceAll("& l t ;", "<") ??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
brasta78
Offline
Joined: 2010-12-30
Points: 0

problem was with SOAP header namespace...