XSD与XML的检测示例代码
16lz
2021-01-22
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);} }}
不抛异常表示检测通过。
更多相关文章
- xml在powerbuilder中应用的代码示例
- dom4j解析xml文件代码示例
- 用Java解析XML文件的代码示例
- c#对xml的CURD操作的代码示例
- 使用FeedTools解析RSS代码示例
- 通过XSLT将xml转换为html的代码示例
- 谈谈Record示例的现状、前景与机遇
- 写了一个 SSO 单点登录的代码示例给胖友!
- flask示例