I have a schema like this
| <xsd:schema xmlns="http://org.jboss.test.osgi.jbossxb.simple"
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://org.jboss.test.osgi.jbossxb.simple"
| elementFormDefault="qualified"
attributeFormDefault="unqualified"
| version="1.0.0">
|
| <xsd:element name="course-booking" type="courseBooking"
/>
| <xsd:complexType name="courseBooking">
| <xsd:sequence>
| <xsd:element ref="company" />
| <xsd:element ref="student" minOccurs="1"
maxOccurs="unbounded" />
| </xsd:sequence>
| <xsd:attribute name="courseReference" type="xsd:string"
use="required" />
| <xsd:attribute name="courseDate" type="xsd:date"
use="required" />
| <xsd:attribute name="invoiceReference" type="xsd:string"
use="required" />
| <xsd:attribute name="totalPrice" type="xsd:decimal"
use="required" />
| </xsd:complexType>
| <xsd:element name="student" type="studentType" />
| <xsd:complexType name="studentType">
| <xsd:attribute name="firstName" type="xsd:string"
use="required" />
| <xsd:attribute name="surname" type="xsd:string"
use="required" />
| </xsd:complexType>
| <xsd:element name="company" type="companyType" />
| <xsd:complexType name="companyType">
| <xsd:sequence>
| <xsd:element name="address" />
| <xsd:element ref="contact" />
| </xsd:sequence>
| <xsd:attribute name="name" type="xsd:string" />
| </xsd:complexType>
| <xsd:element name="contact" type="contactType" />
| <xsd:complexType name="contactType">
| <xsd:attribute name="name" type="xsd:string"
use="required" />
| <xsd:attribute name="telephone" type="xsd:string"
use="required" />
| <xsd:attribute name="email" type="xsd:string"
use="required" />
| </xsd:complexType>
| </xsd:schema>
|
and an xml like this
| <booking xmlns="http://org.jboss.test.osgi.jbossxb.simple"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
| <company name="ACME Consulting">
| <address>10 Coyote Avenue, Arizona, USA</address>
| <contact name="Duke" email="duke(a)acme.com"
telephone="1234567890" />
| </company>
| <student firstName="Jane" surname="Dow" />
| <student firstName="John" surname="Doe" />
| </booking>
|
using this code
| Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
| unmarshaller.setSchemaValidation(true);
| unmarshaller.setNamespaceAware(true);
| unmarshaller.setValidation(true);
|
| URL xsdurl = getResourceURL("simple/booking.xsd");
| assertNotNull("booking.xsd available", xsdurl);
|
| URL xmlurl = getResourceURL("simple/booking.xml");
| assertNotNull("booking.xml available", xmlurl);
|
| JBossEntityResolver entityResolver = new JBossEntityResolver();
| entityResolver.registerLocalEntity(CourseBooking.NAMESPACE_XML_SIMPLE,
xsdurl.toExternalForm());
| unmarshaller.setEntityResolver(entityResolver);
|
| DefaultSchemaResolver schemaBindingResolver = new DefaultSchemaResolver();
| schemaBindingResolver.addClassBinding(CourseBooking.NAMESPACE_XML_SIMPLE,
CourseBooking.class);
|
| CourseBooking booking =
(CourseBooking)unmarshaller.unmarshal(xmlurl.toExternalForm(), schemaBindingResolver);
| assertNotNull("booking not null", booking);
|
I get
| Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Element
{http://org.jboss.test.osgi.jbossxb.simple}booking is not bound as a global element.
| at
org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:641)
| at
org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
| at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
| at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
|
I debugged into SundayContentHandler and found that SchemaBinding
| public ParticleBinding getElementParticle(QName name)
| {
| return elements.get(name);
| }
|
has element "course-booking" registered instead of "booking"
If I change the schema and xml to use course-booking, all works fine.
Why is "booking' not registered?
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4267658#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...