tags:

views:

195

answers:

3

I parse xml using jaxb. I want to parse xml successfully also when xml is not valid that have additional tag. Just ignore tag that non-exist in xsd. Is it possible?

A: 

I'm assuming you mean that you're talking about well-formed XML, but XML which contains elements that are not defined in the schema?

If so, then JAXB is fine with that. Any elements in the input XML which JAXB does not recognise will simply be ignored.

skaffman
@skaffman, What about missing elements ? I mean I have bunch of xml documents without xsd, I generate schema from xml (as it should be), but happens sometimes that there is missing element in one of the xml documents. Could you please point me somewhere how to deal with it ? Is it all about modifying the schema and set the element that are not mandatory? And the objects representing that element would be empty ? I'm deciding whether to use jaxb or build the DOM manually for each xml document, which is not good. But it's a year I used jaxb last time. Thanks in advance
lisak
A: 

My code is below. Jaxb parse succesfully till unknown-tag, after first unknown-tag, for all defined tags warning this tag is not-known tag (print "Unexpected element{}..." message)

`Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setValidating(false); ValidationEventHandler validationHandler = new IwisValidationEventHandler(); unmarshaller.setEventHandler(validationHandler);

public class IwisValidationEventHandler implements ValidationEventHandler { private static Logger logger = Logger.getLogger(IwisValidationEventHandler.class); public boolean handleEvent(ValidationEvent ve) { System.out.println(ve.getMessage); return true; } }`

A: 

You can add xsd:any element



.....

Bina