xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: "Peter Stibrany" <pstibrany AT gmail.com>
- To: xom-interest AT lists.ibiblio.org
- Subject: [XOM-interest] XML Schema validation via JAXP
- Date: Sat, 11 Aug 2007 16:57:37 +0200
Hello,
I use XOM together with JAXP to perform parsing and schema validation
of xml document:
public static Document parse(InputStream documentInputStream)
throws SAXException, ParserConfigurationException, ValidityException,
ParsingException, IOException {
// read schema
InputStream xsdSchema =
Test.class.getResourceAsStream("searchRequest.xsd");
StreamSource ss = new StreamSource(xsdSchema);
// create schema object
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(ss);
// create sax parser, and configure it
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(false);
spf.setSchema(schema);
SAXParser parser = spf.newSAXParser();
// build XOM Document
Builder builder = new Builder(parser.getXMLReader(), false);
Document doc = builder.build(documentInputStream);
return doc;
}
(StreamSource, SchemaFactory, Schema, SAXParserFactory and SAXParser
are from javax.xml packages)
This works for me in Java 1.5, where it throws ParsingException when
document isn't valid. Unfortunately, on Java 6 it returns parsed
document even if it is invalid with respect to schema.
Before I start investigating problem, I'd like to be assured, that
above way of parsing document with schema validation is correct.
Thank you for your support,
-Peter
-
[XOM-interest] XML Schema validation via JAXP,
Peter Stibrany, 08/11/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Elliotte Harold, 08/11/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Peter Stibrany, 08/12/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Elliotte Harold, 08/12/2007
- Re: [XOM-interest] XML Schema validation via JAXP, Peter Stibrany, 08/13/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Elliotte Harold, 08/12/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Peter Stibrany, 08/12/2007
- <Possible follow-up(s)>
- Re: [XOM-interest] XML Schema validation via JAXP, Peter Stibrany, 08/11/2007
-
Re: [XOM-interest] XML Schema validation via JAXP,
Elliotte Harold, 08/11/2007
Archive powered by MHonArc 2.6.24.