Project

Profile

Help

saxon conflicts with jre1.5

Added by Anonymous about 19 years ago

Legacy ID: #3402921 Legacy Poster: tulmat22 (tulmat22)

Hi ! i use jre1.5 to do XML validation. it works fine. i'd like to use SaxonB 8.5.1 to do some XQuery transformations but when i include saxon's librairies in my classpath, XML validation doesn't work anymore. here is the code : import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXParseException; public class XMLValidator { private boolean _isDoccumentValid; public XMLValidator() { _isDoccumentValid = true; } public boolean validateFlow(String xmlFlow, String xsdFlow) { boolean result = false; if ( xmlFlow != null && xsdFlow != null && !xmlFlow.equals("") && !xsdFlow.equals("") ) { StringReader xmlReader = new StringReader(xmlFlow); StringReader xsdReader = new StringReader(xsdFlow); Source src = new StreamSource(xsdReader); InputSource input = new InputSource(xmlReader); if ( input != null && src != null ) result = validate(input, src); } return result; } private boolean validate(InputSource xmlSource, Source xsdSource) { Schema schema = null; Document document = null; Validator validator = null; try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); document = parser.parse(xmlSource); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schema = factory.newSchema(xsdSource); validator = schema.newValidator(); try { validator.validate(new DOMSource(document)); } catch (Exception e) { _isDoccumentValid = false; } } catch (Exception e) { _isDoccumentValid = false; } return _isDoccumentValid; } } here is my schema : <xs:schema xmlns="urn:ietf:params:xml:ns:xcap-error" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ietf:params:xml:ns:xcap-error" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="error-element" abstract="true"/> <xs:element name="xcap-error"> <xs:annotation> <xs:documentation>Indicates the reason for the error.</xs:documentation> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element ref="error-element"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="network-connection" substitutionGroup="error-element"> <xs:annotation> <xs:documentation>This indicates that request could not be completed because of network connection problems</xs:documentation> </xs:annotation> <xs:complexType> <xs:attribute name="phrase" type="xs:string" use="optional"/> </xs:complexType> </xs:element> </xs:schema> here is my xml document : <?xml version="1.0" encoding="UTF-8"?> <xcap-error xmlns="urn:ietf:params:xml:ns:xcap-error"> <network-connection phrase="error message" help=""/> </xcap-error> the document is valid using XMLSpy and java xml validation but when i include saxon libriaires in the classpath i have the following error : org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'xcap-error'. at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109) at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:104) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705) at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:335) at net.sf.saxon.event.ContentHandlerProxy.startContent(ContentHandlerProxy.java:251) at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:182) at net.sf.saxon.event.NamespaceReducer.startContent(NamespaceReducer.java:188) at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:215) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:138) at net.sf.saxon.dom.DOMSender.send(DOMSender.java:92) at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:87) at net.sf.saxon.event.Sender.send(Sender.java:134) at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:28) at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.process(ValidatorImpl.java:220) at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:141) at javax.xml.validation.Validator.validate(Validator.java:82) at src.XMLDocumentValidator.validate(XMLDocumentValidator.java:90) at src.XMLDocumentValidator.validateFlow(XMLDocumentValidator.java:51) at src.test.main(test.java:138) Do you have a solution to use both saxon and xml validation ?


Replies (4)

Please register to reply

RE: saxon conflicts with jre1.5 - Added by Anonymous about 19 years ago

Legacy ID: #3403922 Legacy Poster: Michael Kay (mhkay)

You seem to have got a nasty mixture of Saxon and Xerces/Xalan on your classpath. It's not entirely clear what's going on, but I would suggest that if you build the document using Saxon then you should also validate it using Saxon (which will need Saxon-SA, of course).

RE: saxon conflicts with jre1.5 - Added by Anonymous about 19 years ago

Legacy ID: #3404254 Legacy Poster: Michael Kay (mhkay)

My previous response wasn't very satisfactory. I don't think there's any reason in principle why this shouldn't work. It seems the SchemaFactory is a Xerces schema factory, and you are supplying Xerces with a schema, and constructing a validator using that schema, and when you come to use the validator, Xerces can't locate the schema. I don't know why that should be, but I don't know Xerces very well, and I think you need to ask on a Xerces list rather than here. You're supplying Xerces with a DOMSource that wraps a Saxon document, and you're asking Xerces to read from that DOMSource. It apparently does this by creating an identity transform from a DOMSource to a SAXSource. It's probably expecting to do a Xalan identity transform, but because of your classpath settings, it's actually invoking a Saxon identity transform. Perhaps Xerces is expecting the identity transform to work in a particular way, and has not been tested with third-party identity transformers. I'm sorry, but I'm not going to start debugging Xerces to solve this for you.

I could solve my problem. - Added by Anonymous about 19 years ago

Legacy ID: #3404724 Legacy Poster: nedaji (nedaji)

Thanks for its answers, already I could solve my problem.

RE: saxon conflicts with jre1.5 - Added by Anonymous about 19 years ago

Legacy ID: #3410948 Legacy Poster: tulmat22 (tulmat22)

thanks for your response !

    (1-4/4)

    Please register to reply