[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xml validation
Yes, this can be done by Xerces 2. See the XML Schema how-to page in its documentation and the code snippet below. The extSchemaLocations string is of the form "namespace-uri-1 schema-1 ... namespace-uri-n schema-n " (note that the schemas can be local copies of the 'definitive' ones on the Web). The org.apache.xerces.parsers.DomParser.parse() function takes an org.xml.sax.InputSource. Jeff DomParser parser = new DomParser(); String propId = "http://apache.org/xml/properties/dom/document-class-name"; Object propVal = "org.apache.xerces.dom.PSVIDocumentImpl"; parser.setProperty(propId, propVal); // you may not want all these validation features if ((noNsXsdFilePath != null) || (extSchemaLocationsString != null)) { parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/" + "validation/schema", true); parser.setFeature("http://apache.org/xml/features/" + "validation/schema-full-checking", true); parser.setFeature("http://apache.org/xml/features/" + "dom/include-ignorable-whitespace", false); } //parser.setFeature("http://xml.org/sax/features/" // + "namespace-prefixes", // true); parser.setErrorHandler(new InnerErrorHandler()); if (noNsXsdFilePath != null) { propId = "http://apache.org/xml/properties" + "/schema/external-noNamespaceSchemaLocation"; parser.setProperty(propId, noNsXsdFilePath); } if (extSchemaLocationsString != null) { propId = "http://apache.org/xml/properties" + "/schema/external-schemaLocation"; parser.setProperty(propId, extSchemaLocationsString); } parser.parse(xmlInputSource); Document rv = parser.getDocument(); ----- Original Message ----- From: Brian Shields To: Gerben Rampaart (Casnet Brussel) ; xml-dev@l... Sent: Wednesday, October 09, 2002 6:27 AM Subject: RE: xml validation but is there not a parser out there that i can use that will do something like: Parser p = new Parser(); p.setSchemaLocation(schemaFile.xsd); p.parse(xmlFile.xml);
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|