I'm attempting to use xml beans to parse an xml message. My xml message is:
String xml = <message xmlns='http://www.company.com/common/schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='schema0.xsd' type='Service'>...</message>
If I use the xml above and I call parse using:
MessageDocument.Factory.parse(xml);
I get back a valid MessageDocument object. I'd like to remove the namespace attributes from the xml String and still be able to parse the string using the Factory parser.
For instance:
String xml = <message type='Service'>...</message>
XmlOptions options = new XmlOptions();
Map namespaceMap = new HashMap();
namespaceMap.put("xmlns", "http://www.company.com/common/schema");
namespaceMap.put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaceMap.put("xsi:schemaLocation", "schema0.xsd");
options = options.setLoadAdditionalNamespaces(namespaceMap);
MessageDocument messageDocument = MessageDocument.Factory.parse(xml, options);
This does not work I get:
com.bea.xml.XmlException: error: The document is not a message@http://www.company.com/common/schema: document element namespace mismatch expected "http://www.company.com/common/schema" got ""
I am unable to find any examples of setLoadAdditionalNamespaces, but it seems like this should be the way to supply namespaces other than in the xml message itself.
Any ideas?
Thanks.
--
Dave