users@jaxb.java.net

Re: HOW TO VALIDATE OUR DATA AGAINST THE SCHEMA

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Thu, 30 Sep 2010 08:48:57 +0200

  Hi,

I haven't tried to reproduce your issue yet, but..

is file:/C:/messagingWithSpring/jaxbproject/PublicationSchema.xml
correct path? does the user which is used to run your jaxb app have
sufficient rights to access (open, read) that file?

Pavel


On 9/30/10 7:21 AM, MOTEW wrote:
> hello
>
> i had made a xsd file and perform marshalling and unmarshalling. but i want
> to perform the validation during both marshalling and unmarshalling.i get
> the following in eclipse console when attaching this piece of code
> SchemaFactory sf =
> SchemaFactory.newInstance(
> javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
> Schema schema = sf.newSchema(new File("PublicationSchema.xml"));
> unMarshaller.setSchema(schema);
>
> also m providing my schema file.any help is appreciable.
>
> ""
> Exception in thread "main" org.xml.sax.SAXParseException:
> schema_reference.4: Failed to read schema document
> 'file:/C:/messagingWithSpring/jaxbproject/PublicationSchema.xml', because 1)
> could not find the document; 2) the document could not be read; 3) the root
> element of the document is not<xsd:schema>.
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
> at
> com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2541)
> at
> com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:2528)
> at
> com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1825)
> at
> com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:519)
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:485)
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:210)
> at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
> at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:610)
> at
> com.hp.schemas.publication.publish._2010._9._27.unmarshall.main(unmarshall.java:47)""
>
> my schema file is like this
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xs:schema xmlns="http://www.hp.com/schemas/Publication/publish/2010/9/27"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
> targetNamespace="http://www.hp.com/schemas/Publication/publish/2010/9/27"
> elementFormDefault="qualified" attributeFormDefault="unqualified"
> version="1.87">
> <xs:import namespace="http://www.w3.org/2005/05/xmlmime"
> schemaLocation="http://www.w3.org/2005/05/xmlmime"/>
> <xs:complexType name="Message">
> <xs:sequence>
>
> <xs:element name="MessageInfo">
> <xs:annotation>
> <xs:documentation>Information about Message</xs:documentation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Event" type="EventType" minOccurs="0">
> <xs:annotation>
> <xs:documentation>Subject of the message</xs:documentation>
> </xs:annotation>
> </xs:element>
> <xs:element name="Body" type="MediaType">
> <xs:annotation>
> <xs:documentation>Body of the message</xs:documentation>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> <xs:element name="DeviceInfo">
> <xs:annotation>
> <xs:documentation>Information about Device</xs:documentation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Device" type="DeviceType" minOccurs="0">
> <xs:annotation>
> <xs:documentation>Information about the device</xs:documentation>
> </xs:annotation>
> </xs:element>
> <xs:element name="DeviceId" type="xs:string">
> <xs:annotation>
> <xs:documentation>Id of the Device</xs:documentation>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
>
> </xs:element>
> </xs:sequence>
>
> </xs:complexType>
> <xs:element name="MyBinaryData">
> <xs:complexType>
> <xs:simpleContent>
> <xs:extension base="xs:base64Binary">
> <xs:attribute ref="xmime:contentType" use="required"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:element>
> <xs:simpleType name="EventType">
> <xs:annotation>
> <xs:documentation> Event Types s
> </xs:documentation>
> </xs:annotation>
> <xs:restriction base="xs:NMTOKEN">
> <xs:enumeration value="LowInk"/>
> <xs:enumeration value="FakeCartridge"/>
> <xs:enumeration value="JobStatus"/>
> <xs:enumeration value="NewDevice"/>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="MediaType">
> <xs:annotation>
> <xs:documentation> Message contents that can be Processed
> </xs:documentation>
> </xs:annotation>
> <xs:restriction base="xs:NMTOKEN">
> <xs:enumeration value="Text"/>
> <xs:enumeration value="MyBinaryData"/>
>
>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="DeviceType">
> <xs:annotation>
> <xs:documentation> Devices that can fire the events
> </xs:documentation>
> </xs:annotation>
> <xs:restriction base="xs:NMTOKEN">
> <xs:enumeration value="Printer"/>
> <xs:enumeration value="MobileApps"/>
> <xs:enumeration value="Rover"/>
>
>
> </xs:restriction>
> </xs:simpleType>
>
>
> </xs:schema>
>
>