Working around some malformed XML


XML & Web services: Working around some malformed XML

  1. Working around some malformed XML (1 messages)

    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?
  2. 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