<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

    SchemaValidation .java

    package com.founder.xml;

    import Java.io.IOException;
    import Java.io.InputStream;

    import javax.xml.XMLConstants;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;

    import org.xml.sax.SAXException;

    public class SchemaValidation {

     /**
      * @param args
      * @throws IOException
      * @throws SAXException
      * @throws ParserConfigurationException
      */
     public static void main(String[] args) throws ParserConfigurationException,
       SAXException, IOException {
      SchemaValidation sv = new SchemaValidation();
      sv.validate();
     }

     public void validate() {
      try {
       String strLang = XMLConstants.W3C_XML_SCHEMA_NS_URI;
       SchemaFactory factory = SchemaFactory.newInstance(strLang);

       InputStream isSchema = getClass().getResourceAsStream("/founder.xsd");
       StreamSource ss = new StreamSource(isSchema);
       Schema schema = factory.newSchema(ss);

       Validator validator = schema.newValidator();
       
       InputStream isXML = getClass().getResourceAsStream("/founder.xml");
       
       StreamSource source = new StreamSource(isXML);
       validator.validate(source);
       System.out.println("Result : Valid!");

      } catch (Exception e) {
       e.printStackTrace();
       System.out.println("Result : Invalid!");
      }

     }

    }


    founder.xsd

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns="http://www.founder.com" elementFormDefault="qualified">
     <xs:element name="note">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="to" type="xs:string" />
        <xs:element name="from" type="xs:string" />
        <xs:element name="heading" type="xs:string" />
        <xs:element name="body" type="xs:string" />
       </xs:sequence>
      </xs:complexType>
     </xs:element>
    </xs:schema>


    founder.xml

    <?xml version="1.0"?>
    <note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.founder.com founder.xsd">
     <to>Tove</to>
     <from>Jani</from>
     <heading>Reminder</heading>
     <body>Don't forget me this weekend!</body>
    </note>



    posted on 2008-03-27 21:46 周銳 閱讀(2245) 評論(1)  編輯  收藏 所屬分類: JavaXML
    主站蜘蛛池模板: 亚洲欧洲日本国产| 国产免费牲交视频免费播放| 国产真实伦在线视频免费观看| 国产日韩AV免费无码一区二区三区| 久久久久亚洲av无码专区喷水| 免费观看的av毛片的网站| 中文字幕成人免费高清在线| 亚洲已满18点击进入在线观看| AV在线亚洲男人的天堂| 国产92成人精品视频免费| 色爽黄1000部免费软件下载| 亚洲最新在线视频| 亚洲精品在线视频| 免费精品人在线二线三线区别| aa午夜免费剧场| 亚洲中文字幕久久精品无码A| 国产AV无码专区亚洲Av| 日本一区二区三区日本免费| 老汉精品免费AV在线播放| 日本高清不卡中文字幕免费| 久久久久精品国产亚洲AV无码| 亚洲中久无码永久在线观看同| 在线免费观看一级毛片| 日韩精品无码专区免费播放| 成人免费网站视频www| 天堂亚洲国产中文在线| 亚洲视频在线一区| 国外亚洲成AV人片在线观看| 日韩高清免费观看| 在线观看免费高清视频| 日韩精品无码一区二区三区免费| eeuss影院ss奇兵免费com| 337p日本欧洲亚洲大胆人人| 亚洲AV无码成人专区| 久久精品国产精品亚洲艾| MM131亚洲国产美女久久| 五月天婷亚洲天综合网精品偷| 毛片免费观看视频| 在线视频观看免费视频18| 亚洲一级免费毛片| 99精品在线免费观看|