aspose file tools*
The moose likes XML and Related Technologies and the fly likes XMLBeans: validating derived types in instance documents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XMLBeans: validating derived types in instance documents" Watch "XMLBeans: validating derived types in instance documents" New topic
Author

XMLBeans: validating derived types in instance documents

Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I'm having trouble with something that should work like a dream. I'm using Apache's XMLBeans (2.0.0 and then 2.1.0) to manipulate XML documents: to generate them and to read, validate, extract info from them.

One standard technique in XML Schemas is to define derived types: say B is derived from A by extension. Then, unless you've blocked it, you should be able to use a B element where an A element is expected. So if the xsd defines:
Then you can do the following in a document:
But when I parse and validate, it keeps failing with exception "Invalid xsi:type qname: 'myns:B' in element d@schema-url"! Does anyone know what's going wrong? I've also tried to generate a document in memory, where I call "d.setA(bObject)" to create what I described above, but when I output the XML, there is no xsi:type attribute. I've Googled and found articles like (this: check out section on Extension and Restriction) which make it sound like what I'm doing should work. Help!
[ January 13, 2006: Message edited by: Jeff Albrechtsen ]

There is no emoticon for what I am feeling!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I should mention that the xml document that XMLBeans can't validate is being validated by the XML validator in my IDE (Eclipse), so I don't think I've made a mistake in the document, and the jar file scomp compiled from the XML schema is up-to-date.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XMLBeans: validating derived types in instance documents