Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Validation using JAXB-2.0  RSS feed

carlo sciandrone
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

And here is the java class

Thanks a lot
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!