Unable to parse XML Fragment generated by XMLBeans
As we all know XMLBeans replaces XML root document element with <xml-fragment>. This leads to parsing issues. Wondering if any of the users have encountered similar issues and will be able to help us.
Here is the problem
I am working on developing FaultMappingService using Apache Axis2 and XMLBeans
The incoming request is XML document as shown below
<faul:FaultMappingRequest xmlns:faul="http://integration.xxx.com/public/interfaces/eai/FaultMapping/fault.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faul:Fault>
<faul:domain>sprint</faul:domain>
<faul:service>AAA</faul:service>
<faul:operation>activateDevice</faul:operation>
<faul:faultcode>999</faul:faultcode>
<faul:faultstring>This is value 999</faul:faultstring>
<faul:faultactor>9</faul:faultactor>
<faul:detail>This is detail</faul:detail>
</faul:Fault>
</faul:FaultMappingRequest>
I have a operation called "mapFault()" which takes the above xml document as a argument (i.e. faultMappingRequest0) and extracts the Fault object as shown below
FaultMappingRequest req = faultMappingRequest0.getFaultMappingRequest();
Fault fault = req.getFault();
Now the "fault" object results in XML fragment as shown below
<xml-fragment xmlns:faul="http://integration.clearwire.com/public/interfaces/eai/FaultMapping/fault.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faul:domain>sprint</faul:domain>
<faul:service>AAA</faul:service>
<faul:operation>activateDevice</faul:operation>
<faul:faultcode>123</faul:faultcode>
<faul:faultstring>This is value 123</faul:faultstring>
<faul:faultactor>3</faul:faultactor>
<faul:detail>This is detail</faul:detail>
</xml-fragment>
Then i parse the above XML fragment using XML DOM Parser as shown below
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
String xmlString = faultMappingRequest0.toString();
InputSource is = new InputSource(new StringReader(xmlString));
Document doc = db.parse(is);
Document doc3 = db.parse(xmlString);
The issue is the Document object i.e. doc or doc3 extracted in all different ways using String representation of XML fragment or InputStream representation of XML Fragement or InputSource representation of XML fragment is always NULL. Hence not enabling to parsing XML Fragment.
Then i tried passing complete XML document which results in Malformed Exception as shown below
java.net.MalformedURLException: no protocol: <faul:FaultMappingRequest xmlns:faul="http://integration.xxx.com/public/interfaces/eai/FaultMapping/fault.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faul:Fault>
<faul:domain>sprint</faul:domain>
<faul:service>AAA</faul:service>
<faul:operation>activateDevice</faul:operation>
<faul:faultcode>123</faul:faultcode>
<faul:faultstring>faultcode</faul:faultstring>
<faul:faultactor>9</faul:faultactor>
<faul:detail>This is detail</faul:detail>
</faul:Fault>
</faul:FaultMappingRequest>
I am working on it for week running out of options any help will be greatly appreciated