This discussion is archived
2 Replies Latest reply: Apr 24, 2013 7:20 AM by rp0428 RSS

best way to parse XML's without XSD

jmart Explorer
Currently Being Moderated
Hello,

In the past every time I've had to process XML's I've had an XSD that I could use for marshalling the XML into a bean. But now I have to communicate to an API that returns XML's that do not have any XSD or other type of XML description document.

I was just going to use dumb string parsing and matching. Is there a better way to deal with this? Is there like a tool or library that will take the XML ias input and put it into a generalized container with maps and such that I can yank out the data I want?

thanks
jose
  • 1. Re: best way to parse XML's without XSD
    gimbal2 Guru
    Currently Being Moderated
    Note: there is no best, it makes no sense to ask for it.
    jmart wrote:
    Is there a better way to deal with this? Is there like a tool or library that will take the XML ias input and put it into a generalized container with maps and such that I can yank out the data I want?
    JAXB should be able to do the XML to object hierarchy translation. Its a pretty standard API for which you should be able to find mountains of examples. All you have to basically do is create the proper object hierarchy and put some minimal annotations on it.
  • 2. Re: best way to parse XML's without XSD
    rp0428 Guru
    Currently Being Moderated
    >
    In the past every time I've had to process XML's I've had an XSD that I could use for marshalling the XML into a bean. But now I have to communicate to an API that returns XML's that do not have any XSD or other type of XML description document.

    I was just going to use dumb string parsing and matching. Is there a better way to deal with this? Is there like a tool or library that will take the XML ias input and put it into a generalized container with maps and such that I can yank out the data I want?
    >
    So what is stopping you from creating your own XSD?

    You have to know the basic structure to parse and deal with the data anyway. So why not just capture the structure you need into an XSD and then use that XSD the same way you always have (e.g. XMLBeans or other).

    If you search the net you can find some freeware libraries that can create a basic XSD from an XML doc. The more complete the XML sample is the better job they can do. Use one of those to get the first draft of an XSD and then spruce it up.

    You could also use Apache Commons Digester to just access the raw XML.
    http://commons.apache.org/proper/commons-digester/

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points