新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> XML与数字内容安全(DRM,XrML,RDD, MPEG-21, XACML), XML传输的安全, 基于XML的签名,基于XML的加密
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 XML安全 』 → 请帮忙,有关xsd验证xml文件的疑问! 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 12283 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 请帮忙,有关xsd验证xml文件的疑问! 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     chenbo980 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:52
      门派:XML.ORG.CN
      注册:2007/4/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给chenbo980发送一个短消息 把chenbo980加入好友 查看chenbo980的个人资料 搜索chenbo980在『 XML安全 』的所有贴子 引用回复这个贴子 回复这个贴子 查看chenbo980的博客楼主
    发贴心情 请帮忙,有关xsd验证xml文件的疑问!

    xsd文件如下:
    <?xml version="1.0" encoding="GBK"?>
    <!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by  () -->
    <xs:schema xmlns="http://www.chinatax.gov.cn/dataspec/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.chinatax.gov.cn/dataspec/" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:include schemaLocation="taxDoc.xsd"/>
     <xs:include schemaLocation="taxMLpublic.xsd"/>
     <xs:include schemaLocation="taxMLSkyPublic.xsd"/>
     <xs:complexType name="jhSkySsKkReqest">
      <xs:annotation>
       <xs:documentation>实时扣款请求报文</xs:documentation>
      </xs:annotation>
      <xs:complexContent>
       <xs:extension base="taxDoc">
        <xs:sequence>
         <xs:element name="ssKkItem" type="jhSkySsKkReqBody">
          <xs:annotation>
           <xs:documentation>实时扣款信息</xs:documentation>
          </xs:annotation>
         </xs:element>
        </xs:sequence>
       </xs:extension>
      </xs:complexContent>
     </xs:complexType>
     <xs:complexType name="jhSkySsKkReqBody">
      <xs:annotation>
       <xs:documentation>实时扣款信息</xs:documentation>
      </xs:annotation>
      <xs:sequence>
       <xs:element name="kkXx" type="jhSkySsKkYwxxReq">
        <xs:annotation>
         <xs:documentation>扣款信息</xs:documentation>
        </xs:annotation>
       </xs:element>
       <xs:element name="ywys" type="ywys">
        <xs:annotation>
         <xs:documentation>业务要素</xs:documentation>
        </xs:annotation>
       </xs:element>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>

    根据这个文件生成的xml文件如下:
    <ssKkItem xmlns="http://www.chinatax.gov.cn/dataspec/">
        <kkXx>
            <spxx>
                <sptxx>
                    <xtsphm>asdf</xtsphm>
                    <nsrsbh>asdf</nsrsbh>
                    <nsrmc>asdf</nsrmc>
                    <zsjgDm>c</zsjgDm>
                    <zsjgQc>asdf</zsjgQc>
                    <jkrMc/>
                    <yhzhxx>
                        <yhzlDm>1234</yhzlDm>
                        <yhDm>boc</yhDm>
                        <yhmc>中国银行</yhmc>
                        <yhzh>888888-888</yhzh>
                    </yhzhxx>
                    <skgkDm>asdf</skgkDm>
                    <yszl>a</yszl>
                    <zlqbz>b</zlqbz>
                    <skgkMc>asdf</skgkMc>
                    <kpje>10000.0</kpje>
                    <djzclxDm>c</djzclxDm>
                    <bz1/>
                    <bz2>asdf</bz2>
                </sptxx>
                <kprq>20070328</kprq>
                <szmx>
                    <xh>1</xh>
                    <yskmDm>ssss</yskmDm>
                    <spjkqx>20070320</spjkqx>
                    <sssq>
                        <rqQ>20070201</rqQ>
                        <rqZ>20070228</rqZ>
                    </sssq>
                    <szje>1234.0</szje>
                    <zsxmDm>s</zsxmDm>
                    <zsxmMc>ssss</zsxmMc>
                    <smxx>
                        <xh>1</xh>
                        <zspmDm>11</zspmDm>
                        <zspmMc>smxx111</zspmMc>
                        <sjse>10000.0</sjse>
                        <kssl>1000.0</kssl>
                        <sl>0.22</sl>
                        <yjhkcje>100.0</yjhkcje>
                    </smxx>
                    <smxx>
                        <xh>1</xh>
                        <zspmDm>11</zspmDm>
                        <zspmMc>smxx111</zspmMc>
                        <sjse>10000.0</sjse>
                    </smxx>
                    <param>
                        <name>x</name>
                        <value>rrrssss</value>
                    </param>
                    <param>
                        <name>y</name>
                        <value>ggggggg</value>
                    </param>
                </szmx>
                <szmx>
                    <xh>1</xh>
                    <yskmDm>ssss</yskmDm>
                    <spjkqx>20070320</spjkqx>
                    <sssq>
                        <rqQ>20070201</rqQ>
                        <rqZ>20070228</rqZ>
                    </sssq>
                    <szje>1234.0</szje>
                    <zsxmDm>s</zsxmDm>
                    <zsxmMc>ssss</zsxmMc>
                    <smxx>
                        <xh>1</xh>
                        <zspmDm>11</zspmDm>
                        <zspmMc>smxx111</zspmMc>
                        <sjse>10000.0</sjse>
                    </smxx>
                </szmx>
                <szmx>
                    <xh>1</xh>
                    <yskmDm>cccc</yskmDm>
                    <spjkqx>20070320</spjkqx>
                    <sssq>
                        <rqQ>20070203</rqQ>
                        <rqZ>20070228</rqZ>
                    </sssq>
                    <szje>1234.0</szje>
                    <zsxmDm>sss</zsxmDm>
                    <zsxmMc>test</zsxmMc>
                    <smxx>
                        <xh>1</xh>
                        <zspmDm>11</zspmDm>
                        <zspmMc>smxx111</zspmMc>
                        <sjse>10000.0</sjse>
                    </smxx>
                    <param>
                        <name>x</name>
                        <value>rrrssss</value>
                    </param>
                    <param>
                        <name>y</name>
                        <value>ggggggg</value>
                    </param>
                </szmx>
            </spxx>
            <qsyhxx>
                <sfxysh>aaaaaaaaaaaaaa</sfxysh>
                <qsyhhh>asdf222222</qsyhhh>
            </qsyhxx>
        </kkXx>
        <ywys>
            <zsjgDm>c</zsjgDm>
            <wtrq>20070330</wtrq>
            <jylsh>CD1</jylsh>
        </ywys>
    </ssKkItem>
    使用的验证方法:
    public static boolean isXmlOK(String xsdFile, byte[] tagetXml) throws SAXException, IOException, DocumentException
      {
       boolean flag = true;
       SAXReader reader = new SAXReader();
       reader.setValidation(true);
       
       reader.setFeature("http://xml.org/sax/features/validation", true);
       reader.setFeature("http://apache.org/xml/features/validation/schema", true);
       reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdFile);
       //reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "templateXMLSchema.xsd");

       XMLErrorHandler errorHandler = new XMLErrorHandler();
       reader.setErrorHandler(errorHandler);
       InputStream in = new ByteArrayInputStream(tagetXml);
       InputStreamReader utf8In=new InputStreamReader(in,"utf-8");
       //Document document = reader.read(in);
       reader.read(utf8In);
       XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
       if (errorHandler.getErrors().hasContent()) {
        flag = false;
           writer.write(errorHandler.getErrors());
       } else {
           System.out.println("Xml is OK!.");
       }
       return flag;
      }
    出现的错误为:
    <errors>
      <error column="56" line="1">cvc-elt.1: Cannot find the declaration of element 'ssKkItem'.</error>
    </errors>

    请问各位高手是什么原因呢?帮一下忙嘛。谢谢


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/4/9 16:07:00
     
     glh1023 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:3
      积分:86
      门派:XML.ORG.CN
      注册:2006/8/27

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给glh1023发送一个短消息 把glh1023加入好友 查看glh1023的个人资料 搜索glh1023在『 XML安全 』的所有贴子 引用回复这个贴子 回复这个贴子 查看glh1023的博客2
    发贴心情 
    taxDoc.xsd
      taxMLpublic.xsd
    taxMLSkyPublic.xsd定义在哪里?让我们看全所有的XSD文档.
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/3/11 23:10:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML安全 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/8 14:06:14

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms