File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes XML Validation using JAXB-2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "XML Validation using JAXB-2.0" Watch "XML Validation using JAXB-2.0" New topic
Author

XML Validation using JAXB-2.0

carlo sciandrone
Greenhorn

Joined: Feb 26, 2012
Posts: 5
Hi everybody!!
I have this requirement to fulfill: validate an XML against an Xml Schema ignoring certain attributes.
XML Tutorials suggest the usage of the <xs:anyAttribute> tag for this kind of requests. I've seen that JAXB 2.0 has support for this feature.
So I've annotated my class with a property of type Map<QName,String> and annotation @XmlAttribute.
Then I generated by schemaGen the .xsd (which I pasted below)
To insure validation in my reader class I'm doing this:

If I try with an Xml WITHOUT the added attribute the validation goes well, but if I add a random attribute to my element JAXB complains telling me that the attribute is not defined in the .xsd ("Attribute 'xxxx' is not allowed to appear in element 'modello'")
If I try the validation with tools like Xml spy everything goes fine, so what am I doing wrong?

Here is my xsd definition

And here is my Xml File, where attributeToIgnore is the attribute I added to test validation (if I remove it everything works fine)

Here is my java class Modelli.java

And here is the java class Modello.java

Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Validation using JAXB-2.0
 
Similar Threads
returning a 2-d array
Axis2 POJO web service - wsdl generating xs:anyType
How to make Axis2 bottom-up webservice make minOccurs="1" nillable="false"
annotations on entity class with spring oxm and jaxb for ArrayList
@WebService method returning a custom class containing a HashMap / JAX-WS