我有10 API(2.3.3版)在Android的一个项目,我对XML与XSD文件验证的一个问题。 这是我的code:
I have a project with API 10 (2.3.3 version) in Android and i have a problem for the validation of xml with xsd file. This is my code:
public static Document buildDoc(String xml, String xsd){
// parse an XML document into a DOM tree
Document document = null;
try {
DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parserdb = parserFactory.newDocumentBuilder();
doc = parserdb.parse(new InputSource( new StringReader(xml) ));
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI); //here the emulator raises an exception
Source schemaFile = new StreamSource(new File(xsd));
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(doc));
System.out.println("Validation OK!");
} catch (SAXException e) {
// instance document is invalid!
System.err.println("Validation ERROR!");
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
System.err.println("Validation ERROR!");
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
System.err.println("Validation ERROR!");
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("Validation ERROR!");
e.printStackTrace();
}
return doc;
}
我的Eclipse模拟器抛出一个异常: E / AndroidRuntime(4770):java.lang.IllegalArgumentException异常:产生的原因 http://www.w3.org / 2001 / XML模式
My Eclipse Simulator throw an exception: E/AndroidRuntime(4770): Caused by: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema
在这一行: SchemaFactory的工厂= SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI);
In this line: SchemaFactory factory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI);
为什么?
由于XML模式不支持您的平台。
Because XML Schema isn't supported on your platform.
上一篇:如何使用OSM地图Android应用程序?是否有任何教程,以了解在Android中使用OSM?如何使用、应用程序、有任何、地图
下一篇:错误:无法加载DLL的.dll“:指定的模块找不到。 (从HRESULT异常:0x8007007E) - 这是什么错误?错误、找不到、模块、加载