Posted By:
Anonymous
Posted On:
Thursday, June 3, 2004 10:39 AM
I am trying to validate xml with a schema on the fly. I have been using the Sax parser. I am reading the schema from a db so I have it as a string. The code below works if the schema if specified as a URI. Is there any way to specify the schema as an InputStream? As I can't create tempory files on the server I need some other way. Any help is appriciated Thanks Stephen public static boolean validateSax(String xml, String schema){ try { XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); reader.setFeature("http://xml.org/sax/features/validation",true); reader.set
More>>
I am trying to validate xml with a schema on the fly.
I have been using the Sax parser.
I am reading the schema from a db so I have it as a string.
The code below works if the schema if specified as a URI.
Is there any way to specify the schema as an InputStream?
As I can't create tempory files on the server I need some other way.
Any help is appriciated
Thanks
Stephen
public static boolean validateSax(String xml, String schema){
try {
XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
reader.setFeature("http://xml.org/sax/features/validation",true);
reader.setFeature("http://apache.org/xml/features/validation/schema",true);
reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schema);
reader.parse(new InputSource(new ByteArrayInputStream(xml.getBytes())));
} catch (SAXException e) {
return false
} catch (IOException e) {
return false
}
return true;
}
<<Less