I receive from a WebService an XML result. I didn’t have a XSD file for the xml, but by documentation and some try i figured out an XSD for generating Xmlbean bean for processing the result.
The problem is that the XML i received from the WebService didn’t have any reference to the XSD. So the XmlBean Documente generated from the XSD can’t parse the XML.
For resolving this you need to create an XmlOption object and pass it to the parse method.
Here an example. The Xsd namespace is http://myxsd.acme.it The root element of the XML is MY_RESPONSE.
XmlOptions options = new XmlOptions();
options.setLoadSubstituteNamespaces(Collections.singletonMap("",
"http://myxsd.acme.it "));
options.setLoadReplaceDocumentElement(new javax.xml.namespace.QName(
"http://myxsd.acme.it ", "MY_RESPONSE"));
MYRESPONSEDocument myResponseDocument = MYRESPONSEDocument.Factory
.parse(xmlString options);
I worked this out with the help of this mailing list thread: archive.com/user@xmlbeans.apache.org/msg03236.html
That’s all folks!
Nessun commento:
Posta un commento