简体   繁体   English

用于验证和解析的资源XML

[英]Resource XML for validation and parsing

I have an XML file in the res/xml folder which I want to parse using getXML() . 我要使用getXML()解析的res / xml文件夹中有一个XML文件。

But I also want to validate it first against an XSD schema. 但我也想首先针对XSD架构对其进行验证。

How can I create a InputStreamReader for the XML file for validation? 如何为XML文件创建InputStreamReader以进行验证?
It turns out that to use openRawResource() the file should be under res/raw or in assets 事实证明,要使用openRawResource() ,文件应位于res / raw下资产中

read it from the classpath, getclass -> getresourceasstream. 从类路径读取它,getclass-> getresourceasstream。 For validation consider using the xerces lib. 为了进行验证,请考虑使用xerces库。

Put it under \\res\\xml\\ folder. 将其放在\\ res \\ xml \\文件夹下。 Then you can open it with: 然后,您可以使用以下命令打开它:

 Resources res = activity.getResources();
 XmlResourceParser xrp = res.getXml(R.xml.your_resId);

Please follow below link for XMLResourceParser 请点击以下XMLResourceParser链接

http://android-er.blogspot.com/2010/04/read-xml-resources-in-android-using.html http://android-er.blogspot.com/2010/04/read-xml-resources-in-android-using.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XML ServletContext资源BeanDefinitionStoreException的解析 - Parsing of XML ServletContext resource BeanDefinitionStoreException 未启用带有架构的 Java XML 解析验证 - Java XML parsing validation with schema is not enabled Jaxp xml解析和验证,无需写入文件 - Jaxp xml parsing & validation without writing to file 来自ServletContext资源的意外异常解析XML文档 - Unexpected exception parsing XML document from ServletContext resource 解析错误处理资源路径struts-config.xml - Parsing error processing resource path struts-config.xml 解析器配置异常,解析类路径资源中的XML - Parser configuration exception parsing XML from class path resource IOException 从类路径资源解析 XML 文档 - IOException parsing XML document from class path resource BeanDefinitionStoreException: IOException 从类路径资源 [applicationContext] 解析 XML 文档 - BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext] Spring MVC: IOException 解析来自 ServletContext 资源的 XML 文档 - Spring MVC: IOException parsing XML document from ServletContext resource 使用XMLSchema在配置解析代码中进行XML验证:最佳实践? (Java) - XML Validation in configuration parsing code with XMLSchema: Best Practices? (Java)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM