I parse xml using JAXB
. I want to parse XML
successful开发者_高级运维ly also when XML
is not valid that have additional tag. Just ignore tag that non-exist in XSD
. Is it possible?
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.
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; } }`
You can add xsd:any element
<xsd:complexType name="Type">
<xsd:sequence>
<xsd:element name="root" type="Root"/>
<xsd:any maxOccurs="unbounded" processContents="lax"/>
</xsd:sequence> </xsd:complexType>
.....
精彩评论