KB Article #180543

JSON to XML filter fails with libxml error "Extra content at the end of the document"

Problem

A JSON to XML filter fails with a libxml error saying there's "extra content at the end of the document" similar to the following:


java exception:
org.xml.sax.SAXException: libxml error: : level: 3,
code: 5, file: none, line: 1, str1: "", str2: "", str3: "", int1: 0,
int2: 72, message: Extra content at the end of the document
at com.vordel.jaxprovider.libxml.DocumentBuilderImpl.parseNative(Native Method)
at com.vordel.jaxprovider.libxml.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:55)
at com.vordel.common.xml.XmlParserCache.getDocument(XmlParserCache.java:99)
at com.vordel.circuit.json.JSONToXMLProcessor.invoke(JSONToXMLProcessor.java:122)
at com.vordel.circuit.InvocationEngine.invokeFilter(InvocationEngine.java:148)
at com.vordel.circuit.InvocationEngine.invokeCircuit(InvocationEngine.java:40)
at com.vordel.circuit.InvocationEngine.recordCircuitInvocation(InvocationEngine.java:275)
at com.vordel.circuit.InvocationEngine.processMessage(InvocationEngine.java:237)
at com.vordel.circuit.SyntheticCircuitChainProcessor.invoke(SyntheticCircuitChainProcessor.java:65)
at com.vordel.dwe.http.HTTPPlugin.processRequest(HTTPPlugin.java:420)
at com.vordel.dwe.http.HTTPPlugin.invokeDispose(HTTPPlugin.java:439)
at com.vordel.dwe.http.HTTPPlugin.invoke(HTTPPlugin.java:142)


Resolution


This happens because the JSON being converted has multiple root elements, which are not valid in XML. The JSON to XML filter provides a "virtual root element" setting which needs to be configured in this case to allow the filter to produce valid XML. Refer to the JSON to XML filter's documentation in the Policy Developer Filter Reference for more information and examples of using the virtual root element.