zoukankan      html  css  js  c++  java
  • JBPM流程部署校验之java利用XSD校验XML

    JBPM流程定义校验之java利用XSD校验XML

             上篇我们学习了在.net中怎样利用XSD来验证xml,今天我们来看一下在java中怎样实现利用xsd来校验xml!

            

    /**
     * 
     
    */
    package WFTH;

    import java.io.*;
    import javax.xml.transform.Source;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.validation.*;
    import org.xml.sax.SAXException;

    /**
     * 
    @author 无风听海
     *
     
    */
    public class ValidationManager {
         
    public static String ValidationXmlByXSD(String filePath,String xsdPath,String nameSpace)throws SAXException, IOException {         
             String msg
    =filePath + " is valid.";
             SchemaFactory factory 
    = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
             Schema schema
    =null;
             
    //xml和xsd是独立的文件,否则是内联文件
             if(xsdPath!=null&&xsdPath!=""){
                 File schemaLocation 
    = new File(xsdPath);
                 schema 
    = factory.newSchema(schemaLocation);  
             }
             
    else{
                 schema 
    = factory.newSchema();  
             }        
             Validator validator 
    = schema.newValidator();       
             Source source 
    = new StreamSource(filePath);    
             
    try {
                 validator.validate(source);            
             }
             
    catch (SAXException ex) {
                 msg
    = filePath + " is not valid because "+  ex.getMessage();
             }      
             
    return msg;
         } 
    }


     

  • 相关阅读:
    tomcat war包自动化部署脚本
    nginx只允许域名访问,禁止ip访问
    Nginx Errors: upstream response cache error
    Linux进程的睡眠和唤醒
    传输层:UDP 协议
    IP网际协议
    应用层协议
    [Eclipse插件] Eclipse设置Tab键为空格(ctrl+shirt+f格式化生效)!
    [Android Pro] 使用CursorLoader异步加载数据 from 3.0
    [Android Memory] 内存分析工具 MAT 的使用
  • 原文地址:https://www.cnblogs.com/wufengtinghai/p/2137672.html
Copyright © 2011-2022 走看看