• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in XSD Parsing - Imported XSD not being loaded

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to validate XML with XSD. The XML has elements in two different namespaces:-

1-"http://schemas.xmlsoap.org/soap/envelope/"
2-urn:Hotel_Reserve

So in Schema I have defined elements Envelop, Header and Body in "http://schemas.xmlsoap.org/soap/envelope/" namespace and targetNamespace and imported another schema which is in "urn:Hotel_Reserve" namespace. Here it is:-

<xs:schema xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n1="urn:Hotel_Reserve" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" elementFormDefault="qualified">
<xs:import namespace="urn:Hotel_Reserve" schemaLocation="BookingRequestBody.xsd"/>
<xs:element name="Envelope">
<xs:complexType>
<xs:sequence>
<xs:element name="Header">
<xs:complexType/>
</xs:element>
<xs:element name="Body">
<xs:complexType>
<xs:sequence>
<xs:element ref="n1:DS_HotelRes_RQ"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

I am using JDK1.5. I am able to validate the XML in a standalone Java program. I suppose here the Xerces parse is being used which is shipped with JDK itself in com.sun.org.apache.xerces* package.

The problem is when the same code is deployed in JBoss 4.0.3SP1, I get following exception:-
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'n1:DS_HotelRes_RQ' to a(n) 'element declaration' component.

It seems that when the code is deployed in JBoss, and the main XSD(which is mentioned above) is loaded and parsed, the schema in the import section is not loaded. I have checked the schema are present in the required place.

Any clue where I may be doing wrong?
 
Sarah Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of parsing the schema with DOM/SAX, just loading it with URL worked with JBoss.
But I don’t know how and why?
here is the sample code:



URL schemaURL = Thread.currentThread().getContextClassLoader().getResource(WSConstants.BOOKING_SCHEMA_FILE);

SchemaFactory provBookingSchemaFactory = schemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); provBookingSchemaFactory.setErrorHandler(new InvalidXMLErrorHandler());
Schema provBookingSchema = provBookingSchemaFactory.newSchema(schemaURL);
Validator provBookingValidator = provBookingSchema.newValidator();
provBookingValidator.validate(new DOMSource(requestDoc));

Earlier I was creating the schema instance using the DOM source:-


Schema provBookingSchema = provBookingSchemaFactory.newSchema(new DOMSource(schemaDoc));
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's because the schema location is a relative URL. So if you give the parser a URL, it has a base URL to apply the relative URL to. If you give the parser a DOM, it doesn't.
 
Sarah Jones
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this makes sense.
But the question is how come the schema factory is able to load the imported schema when the schema is given as a DOM source in a standalone Java program. I faced the problem when the code was being run in JBoss server.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Presumably if the resolver doesn't have a base URL, it falls back on using the current working directory for that. If you happened to have that imported schema in the current working directory, it would work by accident.
 
reply
    Bookmark Topic Watch Topic
  • New Topic