OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] xml validation

[ Lists Home | Date Index | Thread Index ]

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@lists.xml.org
Sent: Wednesday, October 09, 2002 6:27 AM
Subject: RE: [xml-dev] 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);





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS