1 Reply Latest reply on Feb 20, 2009 2:24 AM by Saurabh Gupta

    JBoss4.0.3SP1 | Issues with  Parsing XML Schema importing an

    Saurabh Gupta Newbie

      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="n1S_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 'n1S_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?

        • 1. Re: JBoss4.0.3SP1 | Issues with  Parsing XML Schema importin
          Saurabh Gupta Newbie

          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));