XML : JAXB Cannot find the declaration of element 'xs:schema'.] weeor

While running the below code and facing with exception. I have posted xml and schema below. Any help will be appreciated

     JAXBContext jaxbContext = JAXBContext.newInstance(com.amex.moebius.jaxb.ObjectFactory.class);  SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);  Schema schema = factory.newSchema(new StreamSource(new File("gateKeeperValidations.xsd")));  Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();  jaxbUnmarshaller.setSchema(schema);  ValdationConfigType ts = (ValdationConfigType) JAXBIntrospector.getValue(jaxbUnmarshaller.unmarshal(new StreamSource(new File("gateKeeperValidations.xsd")),ValdationConfigType.class));  ValdationConfigType ts = (ValdationConfigType)jaxbUnmarshaller.unmarshal(new File(Validation.xml"));  System.out.println(ts.getValidations());    

A getting the below exceptions:

  [org.xml.sax.SAXParseException; systemId: file:/F:/gateKeeperValidations.xsd; lineNumber: 2; columnNumber: 161; cvc-elt.1: Cannot find the declaration of element 'xs:schema'.]`enter code here`    

Below is my xml and XSD

  <?xml version="1.0" encoding="UTF-8"?>  <valdationConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                   xmlns="http://www.aexp.com/"                   xsi:schemaLocation="http://www.aexp.com/ gatekeeperValidations.xsd">    <validations>  <columns>      <column number="1">          <rule>              <field empty="false"></field>              <field format="mm/dd/yyyy"></field>              <field length="1" type="greaterThan"></field>          </rule>      </column>      <column number="2">          <rule>              <field empty="false"></field>              <field format="mm/dd/yy"></field>              <field length="2" type="lessThan"></field>          </rule>      </column>      <column number="3">          <rule>              <field empty="false"></field>              <field format="dd/mm/yyyy"></field>              <field length="2" type="equalTo"></field>          </rule>      </column>  </columns>  </validations>      </valdationConfig>    
  <?xml version="1.0" encoding="UTF-8"?>  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.aexp.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">    <xs:element name="valdationConfig" type="aexp:valdationConfigType" xmlns:aexp="http://www.aexp.com/"/>    <xs:complexType name="validationsType">      <xs:sequence>        <xs:element type="aexp:columnsType" name="columns" xmlns:aexp="http://www.aexp.com/"/>      </xs:sequence>    </xs:complexType>    <xs:complexType name="fieldType">      <xs:simpleContent>        <xs:extension base="xs:string">          <xs:attribute type="xs:string" name="empty" use="optional"/>          <xs:attribute type="xs:string" name="format" use="optional"/>          <xs:attribute type="xs:string" name="length" use="optional"/>          <xs:attribute type="xs:string" name="type" use="optional"/>        </xs:extension>      </xs:simpleContent>    </xs:complexType>    <xs:complexType name="columnsType">      <xs:sequence>        <xs:element type="aexp:columnType" name="column" maxOccurs="unbounded" minOccurs="0" xmlns:aexp="http://www.aexp.com/"/>      </xs:sequence>    </xs:complexType>    <xs:complexType name="valdationConfigType">      <xs:sequence>        <xs:element type="aexp:validationsType" name="validations" xmlns:aexp="http://www.aexp.com/"/>      </xs:sequence>    </xs:complexType>    <xs:complexType name="columnType">      <xs:sequence>        <xs:element type="aexp:ruleType" name="rule" xmlns:aexp="http://www.aexp.com/"/>      </xs:sequence>      <xs:attribute type="xs:string" name="number" use="optional"/>    </xs:complexType>    <xs:complexType name="ruleType">      <xs:sequence>        <xs:element type="aexp:fieldType" name="field" maxOccurs="unbounded" minOccurs="0" xmlns:aexp="http://www.aexp.com/"/>      </xs:sequence>    </xs:complexType>  </xs:schema>  

Please help, am not sure where am going wrong Thanks

No comments:

Post a Comment