1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
InputSource in = new InputSource(xml);
SAXParser parser = new SAXParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
if (withNameSpace){
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",xsd);
}
else {
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",xsd);
}
XmlCCHandler parseXmlCC = new XmlCCHandler();
parser.setErrorHandler(parseXmlCC);
parser.setContentHandler(parseXmlCC);
parser.parse(in); |
Partager