通过xsd验证xml格式是否正确
答案:1 悬赏:50 手机版
解决时间 2021-01-27 10:18
- 提问者网友:留有余香
- 2021-01-27 05:02
通过xsd验证xml格式是否正确
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-01-27 06:42
*
*
* 使用范例说明
* * @author 赞同科技
public static final String XSD_RCD ="/schema/rcd.xsd";
public static boolean validateXml(InputStream xml,InputStream xsd){try{final String schema_uri =XMLConstants.W3C_XML_SCHEMA_NS_URI;
SchemaFactory factory =SchemaFactory.newInstance(schema_uri);
Schema schema =factory.newSchema(new StreamSource(xsd));
Validator val =schema.newValidator();
val.validate(new StreamSource(xml));
}catch(Exception e){
//TODO log,将详细信息记录.log
* * @author 赞同科技
public static final String XSD_RCD ="/schema/rcd.xsd";
public static boolean validateXml(InputStream xml,InputStream xsd){try{final String schema_uri =XMLConstants.W3C_XML_SCHEMA_NS_URI;
SchemaFactory factory =SchemaFactory.newInstance(schema_uri);
Schema schema =factory.newSchema(new StreamSource(xsd));
Validator val =schema.newValidator();
val.validate(new StreamSource(xml));
}catch(Exception e){
//TODO log,将详细信息记录.log
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯