Monday, 8 December 2014

Error parsing XSD document



I am trying to validate that an xml document adheres to an xsd specification using Java.


Here is my java code:



SchemaFactory factory =
SchemaFactory.newInstance("http://ift.tt/tphNwY");

File schemaLocation = new File("XX_ASN.xsd");
Schema schema = factory.newSchema(schemaLocation); //**Error occurs here**

Validator validator = schema.newValidator();


String xmlFile="file://18828324.txt";
Source source = new StreamSource(xmlFile);

// 5. Check the document
try {
validator.validate(source);
System.out.println(args[0] + " is valid.");
}
catch (SAXException ex) {
System.out.println(args[0] + " is not valid because ");
System.out.println(ex.getMessage());
}


Here is the error i am getting



org.xml.sax.SAXParseException; systemId: file:/C:/workspace4.3/MMSV/XX_ASN.xsd; lineNumber: 14; columnNumber: 19; s4s-elt-must-match.1: The content of 'XXLocalDeliveryAsnPost' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complexType.


And here is my xsd file:



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://ift.tt/tphNwY" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="XXLocalDeliveryAsnPost">
<xs:annotation>
<xs:documentation>Post ASN data to XX Local Delivery</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="VendorId" type="xs:string">
<!-- Name of Vendor provided by XX -->
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="AsnData">
<xs:annotation>
<xs:documentation>ASN for each truck</xs:documentation>
</xs:annotation>

<xs:complexType>
<xs:element name="ShipOrigin" type="xs:string"/>
<xs:element name="Scac" type="xs:string">
<!-- Will store upto 4 characters -->
</xs:element>
<xs:element name="VehicleId" type="xs:string">
<!-- Will store upto 20 characters -->
</xs:element>
<xs:element name="BolNumber" type="xs:string">
<!-- Will store upto 8 characters -->
</xs:element>
<xs:element name="VendorShipDateToXX" type="xs:string">
<!-- YYYYMMDD Format -->
</xs:element>
<xs:element name="VendorArrivalDateAtXX" type="xs:string">
<!-- YYYYMMDD Format -->
</xs:element>
<xs:element name="VendorArrivalTimeAtXX" type="xs:string">
<!-- HHMM Miltary Format -->
</xs:element>
<xs:element name="OrderData">
<xs:annotation>
<xs:documentation>Order Data</xs:documentation>
</xs:annotation>

<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="XXOrderNumber" type="xs:string"/>
<xs:element name="VendorShipDateToXX" type="xs:string">
<!-- YYYYMMDD Format -->
</xs:element>
<xs:element name="ModelData">
<xs:annotation>
<xs:documentation>Model Data</xs:documentation>
</xs:annotation>

<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="ModelNumber" type="xs:string">
<!-- Will store upto 20 characters -->
</xs:element>
<xs:element name="SerialNumber" type="xs:string">
<!-- Will store upto 30 characters -->
</xs:element>
<xs:element name="WeightInPounds" type="xs:string">
<!-- Format 999.999 Weight in Pounds (lbs) -->
</xs:element>
<xs:element name="LengthInInches" type="xs:string">
<!-- Format 999.999 Length in Inches -->
</xs:element>
<xs:element name="WidtInInches" type="xs:string">
<!-- Format 999.999 Width in Inches -->
</xs:element>
<xs:element name="HeightInInches" type="xs:string">
<!-- Format 999.999 Height in Inches -->
</xs:element>
<xs:element name="ModelFreightCode" type="xs:string">
<!-- Will store upto 6 characters -->
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>


The problem occurs in the start of second complexType of XXLocalDeliveryAsnPost (line 14)


what am i doing wrong here? The xsd document was provided by someone else and cannot be changed.


No comments:

Post a Comment