Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
2.9.0
-
None
-
None
-
Spring Framework 2.5.5
CXF 2.1.3
Java 1.5
Description
Ok - I have been struggling with this for over two weeks now and am about to pull out my hair. I have scrubbed discussion groups, websites for help but alas I come up with nothing. I am trying to validate an XML file against the XSD schema and running into some problems. The XML I would like to validate is the payload of a web service SOAP message. I am using the SAXParserFactory to generate my parser and I am doing the following in my code to set up the parser:
System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema", "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
parserFactory.setValidating(false);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema", true);
parserFactory.setFeature("http://xml.org/sax/features/validation", true);
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
StreamSource soapSchemaSource = new StreamSource(new ClassPathResource(soapSchemaVersion).getInputStream());
soapSchemaSource.setSystemId("http://schemas.xmlsoap.org/soap/envelope/");
StreamSource schemaSource = new StreamSource(new ClassPathResource("arm-internal.xsd").getInputStream());
schemaSource.setSystemId("http://service.arm.hud.gov/");
parserFactory.setSchema(schemaFactory.newSchema(new Source[]
{schemaSource, soapSchemaSource}));
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
ArmHandler handler = new ArmHandler();
reader.setErrorHandler(handler);
reader.parse(new InputSource(payload));
I get no errors setting up my schema but yet when I try to parse a XML file using the schema specified in newSchema, I get the following exception:
"org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'OpenDNS'"
It is followed by a stack trace.
My schema actually imports 2 external schemas and when I specify their schema location as a URL, not a local file, it works but i can not rely on that because I do not have access to the internet.
I can attach my XML and XSD files but there is no place to do so. I will add them at the end.
Here are my questions/issues:
1. How do I solve the problem above from happening other than relying on the internet to find the schema.
2. When I do modify my XML file, the above exception is corrected but then I get an error saying it can not resolve the soapenv namespace.
3. Ultimately what I am interested in is getting the parser to validate my XML correctly. It is intentionally flawed - there is a bug in our system I am trying to correct. We were previously using XMLValidator (from Spring) but it has no ability to configure/customize so I switched to use the SAXParser. Ultimately, I need the validator to complain when an element is missing. In my XML below, I am missing the required element of referenceId but the parser does not complain about it. Incidentally, it does not matter if I supply the namespace or not in my XML file since I am specifying the XSD in the application code in terms of it validating the XML correctly.
Thank you so much
Brenda
Here they are inline:
XSD:
<xs:schema xmlns="http://service.arm.hud.gov/"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://service.arm.hud.gov/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.w3.org/2004/08/xop/include" schemaLocation="xop-include.xsd"/>
<xs:import namespace="http://www.w3.org/2005/05/xmlmime" schemaLocation="xmime.xsd"/>
<xs:simpleType name="nonNegativeInt">
<xs:restriction base="xs:int">
<xs:minInclusive value="0"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="zeroOrOne">
<xs:restriction base="xs:int">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="threeDigitNumber">
<xs:restriction base="xs:int">
<xs:totalDigits value="3"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="processingSuccessful" type="xs:boolean"/>
<xs:element name="submissionRequestStatus" type="nonNegativeInt"/>
<xs:element name="processingErrorDescription" type="xs:string"/>
<xs:element name="agcName" type="xs:string"/>
<xs:element name="message" type="xs:string"/>
<xs:element name="systemName" type="threeDigitNumber"/>
<xs:element name="id" type="xs:int"/>
<xs:element name="longDesc" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="shortDesc" type="xs:string"/>
<xs:element name="agcHcsId" type="nonNegativeInt"/>
<xs:element name="referenceId" type="nonNegativeInt"/>
<xs:element name="submissionId" type="xs:long"/>
<xs:element name="statusDate" type="xs:dateTime"/>
<xs:element name="subFlag" type="zeroOrOne"/>
<xs:element name="getSubmissionInfoResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="statusDate"/>
<xs:element minOccurs="1" ref="statusMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="statusMessage">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="NOT FOUND"/>
<xs:pattern value="RECEIVED"/>
<xs:pattern value="PROCESSING"/>
<xs:pattern value="DONE"/>
<xs:pattern value="ERROR[:][\s\S]*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="pingResponse">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="ARM Service Version 3[.]1.*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="getReferenceResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="referenceItem" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getReference">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="agcHcsId"/>
<xs:element minOccurs="1" ref="referenceId"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ping">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="agcHcsId"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="throwFault">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="agcHcsId"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getSubmissionInfo">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="agcHcsId"/>
<xs:element minOccurs="1" ref="submissionId"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="postSubmission">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="submissionHeader"/>
<xs:element minOccurs="1" ref="submissionData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="postSubmissionResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="submissionId"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="submissionData">
<xs:complexType mixed="true">
<xs:sequence minOccurs="0">
<xs:element ref="xop:Include"/>
</xs:sequence>
<xs:attribute ref="xmime:contentType" use="optional" fixed="text/xml"/>
<xs:anyAttribute namespace="http://www.w3.org/2004/11/xmlmime" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="submissionHeader">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="agcHcsId"/>
<xs:element minOccurs="1" ref="agcName"/>
<xs:element minOccurs="1" ref="systemName"/>
<xs:element minOccurs="1" ref="subFlag"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="referenceItem">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" ref="id"/>
<xs:element minOccurs="1" ref="longDesc"/>
<xs:element minOccurs="1" ref="name"/>
<xs:element minOccurs="1" ref="shortDesc"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML File:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<getReference>
<agcHcsId>80000</agcHcsId>
</getReference>
</soapenv:Body>
</soapenv:Envelope>