How to create XML validator from XML schema?
2015-08-11 13:08
363 查看
How to create XML validator from XML schema?
public static void main(String[] args) throws Exception { // http://www.java-tips.org/java-se-tips-100019/170-javax-xml-validation/1733-how-to-create-xml-validator-from-xml-schema.html try { // define the type of schema - we use W3C: String schemaLang = XMLConstants.W3C_XML_SCHEMA_NS_URI; // get validation driver: SchemaFactory factory = SchemaFactory.newInstance(schemaLang); // create schema by reading it from an XSD file: Schema schema = factory.newSchema(new StreamSource( "BuildInstall.xsd")); Validator validator = schema.newValidator(); // at last perform validation: validator.validate(new StreamSource("Install.xml")); } catch (SAXException | IOException ex) { // we are here if the document is not valid: // ... process validation error... ex.printStackTrace(); } }
相关文章推荐
- XML 与 JSON 优劣对比
- As3.0 xml + Loader应用代码
- 网马生成器 MS Internet Explorer XML Parsing Buffer Overflow Exploit (vista) 0day
- ext读取两种结构的xml的代码
- PostgreSQL教程(二):模式Schema详解
- Validation of viewstate MAC failed.的解决方法
- C#针对xml基本操作及保存配置文件应用实例
- asp下查询xml的实现代码
- sqlserver FOR XML PATH 语句的应用
- 使用sp_xml_preparedocument处理XML文档的方法
- C#中的Linq to Xml详解
- C#操作XML文件实例汇总
- SQL Server中的XML数据进行insert、update、delete
- jQuery 1.3 和 Validation 验证插件1.5.1
- SQL Server中的XML数据进行insert、update、delete操作实现代码
- 关于SQLServer2005的学习笔记 XML的处理
- C#通过DataSet读写xml文件的方法
- php xml 入门学习资料
- Zend 输出产生XML解析错误