You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jared Davis <ja...@cs.utexas.edu> on 2004/09/29 17:55:36 UTC

DOM and Validation

Hi,

I'm trying to parse some XML files (which will be written by hand)
and validate them against a schema (which will be somewhere on the
end user's system, and found using getResource).  So, I am thinking
that I don't want to have the XML files themselves specify an
explicit location, but instead I'd like to just load the schema
manually and check the files against it.

I don't seem to be having much luck with this.  Here's what I'm
trying to do:


   // Open a stream to the file to read.
   InputStream in = ...;

   // Create a Schema object with my xsd file
   SchemaFactory scf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
   Schema schema = scf.newSchema(getClass().getResource("fog.xsd"));

   // Create a DocumentBuilderFactory and set its schema
   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   dbf.setSchema(schema);

   // Create a DocumentBuilder and parse the file.
   DocumentBuilder db = dbf.newDocumentBuilder();
   Document doc = db.parse(in);



Anyway, when I run this code, I get the attached error trace.  The
error will not occur if I don't set the schema.  Perhaps I'm not
doing this in the proper way?

Thanks,
    Jared




java.lang.IllegalStateException
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.checkState(ValidatorHandlerImpl.java:411)
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.getElementTypeInfo(ValidatorHandlerImpl.java:441)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.elementAug(JAXPValidatorComponent.java:299)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.endElement(JAXPValidatorComponent.java:291)
         at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
         at com.sun.org.apache.xerces.internal.jaxp.validation.XNI2SAXEx.endElement(XNI2SAXEx.java:108)
         at 
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:818)
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:339)
         at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent.endElement(JAXPValidatorComponent.java:206)
         at 
com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler.endElement(XIncludeHandler.java:790)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
         at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:248)
         at 
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: DOM and Validation

Posted by Ankit Pasricha <an...@ca.ibm.com>.
See the 'http://apache.org/xml/properties/schema/external-schemaLocation' 
property in [1]

[1] http://xml.apache.org/xerces2-j/properties.html

Ankit Pasricha
XML Parser Development
IBM Toronto Lab
8200 Warden Avenue, Ontario L6G 1C7
Phone: (905) 413 4941



Jared Davis <ja...@cs.utexas.edu> 
09/29/2004 11:55 AM
Please respond to
xerces-j-user@xml.apache.org


To
xerces-j-user@xml.apache.org
cc

Subject
DOM and Validation






Hi,

I'm trying to parse some XML files (which will be written by hand)
and validate them against a schema (which will be somewhere on the
end user's system, and found using getResource).  So, I am thinking
that I don't want to have the XML files themselves specify an
explicit location, but instead I'd like to just load the schema
manually and check the files against it.

I don't seem to be having much luck with this.  Here's what I'm
trying to do:


   // Open a stream to the file to read.
   InputStream in = ...;

   // Create a Schema object with my xsd file
   SchemaFactory scf = 
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
   Schema schema = scf.newSchema(getClass().getResource("fog.xsd"));

   // Create a DocumentBuilderFactory and set its schema
   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   dbf.setSchema(schema);

   // Create a DocumentBuilder and parse the file.
   DocumentBuilder db = dbf.newDocumentBuilder();
   Document doc = db.parse(in);



Anyway, when I run this code, I get the attached error trace.  The
error will not occur if I don't set the schema.  Perhaps I'm not
doing this in the proper way?

Thanks,
    Jared




java.lang.IllegalStateException
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.checkState(ValidatorHandlerImpl.java:411)
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.getElementTypeInfo(ValidatorHandlerImpl.java:441)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.elementAug(JAXPValidatorComponent.java:299)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.endElement(JAXPValidatorComponent.java:291)
         at 
com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.XNI2SAXEx.endElement(XNI2SAXEx.java:108)
         at 
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:818)
         at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:339)
         at 
com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
         at 
com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent.endElement(JAXPValidatorComponent.java:206)
         at 
com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler.endElement(XIncludeHandler.java:790)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
         at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
         at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
         at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
         at 
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:248)
         at 
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org