Reputation: 39
I tried to unmarshall the xml resulted in saxparser exception because the value of a element has a tag element which is not properly closed. It is what I get and have to process.
Here is the sample xml -
<GetResultResponse>
<ExecutionID>17716868</ExecutionID>
<Device>STLMJWB</Device>
<Status>Success</Status>
<ResultSet>
<Command>RTRV-ALM-ALL:STLMJWB0201000003FIS:ALL:<ctag=dq>;</Command>
<CommandType>Raw</CommandType>
<commandResult>Success</commandResult>
<ResultSet>
</GetResultResponse>
The above xml contains along with other string as value of command and the tag is not properly closed resulting in the following exception -
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 212; Element type "ctag" must be followed by either attribute specifications, ">" or "/>".]
The xml input to unmarshall is fed as string reader
StringReader sr = new StringReader("ABOVE XML");
unmarshaller.unmarshal(sr);
I have two classes - One for GetResultResponse and other for ResultSet.
Things I tried to sort out - 1. CharacterEscapeHandler - Got error when I assigned this proerpty to Unmarshaller because only marshaller accepts this. 2. XmlJavaTypeAdapter - Unmarshalling happens before processing and returning values from Adapter. 3. BeforeUnmarshall - Set listener to unmarshaller; Returns null for command. 4. XmlMixed and XmlAnyElement - Expects proper closing tag.
Pleae let me know if you have any doubts. Thanks in Advance
Upvotes: 2
Views: 984
Reputation: 149017
Your XML as it currently is, is not valid. You need to properly escape the text content here:
<Command>RTRV-ALM-ALL:STLMJWB0201000003FIS:ALL:<ctag=dq>;</Command>
As
<Command>RTRV-ALM-ALL:STLMJWB0201000003FIS:ALL:<ctag=dq>;</Command>
Upvotes: 1