xml与xsd的匹配性检测示例

import java.io.File;import javax.xml.transform.Source;import javax.xml.transform.stream.StreamSource;import javax.xml.validation.SchemaFactory;public class XmlHandler {public static final String XSD_FILE_PATH = "automation.xsd";    public static void checkXSD(File xmlFile)  {         SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");    try {    schemaFactory.newSchema(                    new Source[] {                    new StreamSource(                    Thread.currentThread().getContextClassLoader().getResourceAsStream(XSD_FILE_PATH))}                    ).newValidator().validate(new StreamSource(xmlFile));} catch (Exception e) {throw new RuntimeException("XSD检测失败",e);}    }}

不抛异常表示检测通过。

更多相关文章

  1. xml在powerbuilder中应用的代码示例
  2. dom4j解析xml文件代码示例
  3. 用Java解析XML文件的代码示例
  4. c#对xml的CURD操作的代码示例
  5. 使用FeedTools解析RSS代码示例
  6. 通过XSLT将xml转换为html的代码示例
  7. 谈谈Record示例的现状、前景与机遇
  8. 写了一个 SSO 单点登录的代码示例给胖友!
  9. flask示例

随机推荐

  1. 获取拆分字符串数组的最后一个元素
  2. 我可以更改javascript“this”的上下文吗
  3. FusionCharts的Line.swf做法,我想出现2条
  4. jQuery:执行一个函数AFTER toggleClass被
  5. jquery 更改angularJS input 内容导致绑
  6. 等待执行所有ajax回调的最佳解决方案
  7. AngularJs location.path没有传递参数
  8. « VS 2010 和 .NET 4.0 系列之《VS 2010
  9. 在多个文件中需要相同的模块
  10. 获取JavaScript数组元素的最大长度