XML & Web services: Working around some malformed XML
- Posted by: Viktor Lundstr??m
- Posted on: December 22 2004 05:24 EST
I have a problem.
I'm trying to parse the return values from a XML web API, and the XML is a bit misformed:
This gives me an exception when trying to parse it with Xerces:
The prefix "abc" for element "abc:whatever" is not bound.
Now, I can't insert a namespace declaration into the document, since, well, it isn't parsed. I can't make the API change its output since it's a third party and I'm tight on time. And I can't prepend XML.
Is there a way to disable namespace handling in Xerces 2? To make it just view "abc:whatever" as a name?
If you have access to the non-parsed content, just put the namespace declaration manually before parsing the XML.
StirngBuffer xml = new StringBuffer(xmlText);
xml.insert(xmlText.indexOf(">")," xmlns:abc=\"some bogus uri\"");
That's given if, again, you have access to your xml content and the structure is always like the one you've specified, in case of possible declaration, you can rip it out before inserting the namepsace(s).
Artem D. Yegorov