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

    >> DTD, XML Schema(XMLS), RELAX NG
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DTD/XML Schema 』 → 新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4236 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     world39 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:0
      积分:53
      门派:XML.ORG.CN
      注册:2007/8/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给world39发送一个短消息 把world39加入好友 查看world39的个人资料 搜索world39在『 DTD/XML Schema 』的所有贴子 引用回复这个贴子 回复这个贴子 查看world39的博客楼主
    发贴心情 新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load?

    新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load?
    books.xml

    <?xml version='1.0'?>
    <Collection xmlns="x-schema:books">
       <Book>
        <Title>Lover Birds</Title>
        <Author>Cynthia Randall</Author>
           <Title>Lover Birds</Title>
           <Title>the secord title</Title>
           <Title>the third title</Title>  
          <Publisher>Lucerne Publishing</Publisher>
       </Book>
    </Collection>

    books.xsd
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:element name="Collection">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="OtherBook">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Title" type="xs:string" maxOccurs="1" />
                  <xs:element name="Author" type="xs:string" />
                  <xs:element name="Publisher" type="xs:string" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    用vc写的验证的接口

    bool   CURLManagerApp::schemas()
    {
        ::CoInitialize(NULL);
       IXMLDOMDocument2Ptr pIXMLDOMDocument2;
       IXMLDOMSchemaCollection2Ptr pIXMLDOMSchemaCollection2Ptr;
       int nResult;
       
       try
       {
       // Create the DOM
          nResult = pIXMLDOMDocument2.CreateInstance(__uuidof(MSXML2::DOMDocument40));
          (nResult == 0) ? 0: throw nResult;

       // Create the Schema Collections
          nResult = pIXMLDOMSchemaCollection2Ptr.CreateInstance(__uuidof(MSXML2::XMLSchemaCache40));
          (nResult == 0) ? 0: throw nResult;
       
       // Add the schema to the collection
          nResult = pIXMLDOMSchemaCollection2Ptr->add(_T("x-schema:books"), _T("books.xsd"));
          (nResult == 0) ? 0: throw nResult;
          
       // Attach schemas
          pIXMLDOMDocument2->schemas = pIXMLDOMSchemaCollection2Ptr.GetInterfacePtr();

          pIXMLDOMDocument2->async = false;
          pIXMLDOMDocument2->validateOnParse = true;

       // Load the document into the DOM
          nResult = pIXMLDOMDocument2->load(_T("books.xml"));
          (nResult == -1) ? 0: throw nResult;

       
          ::MessageBox(NULL, pIXMLDOMDocument2->xml, _T("Loaded Document"), MB_OK);
       } catch(...)
       {
          ::MessageBox(NULL, _T("Sample Failed"), _T("Error"), MB_OK);
       }
       ::CoUninitialize();
       return true;

    }

    这个books.xml中 autor 和title的顺序不符合books.xsd,而且title也出现了不止1次,为什么在程序中books.xml还是会正常导入呢? 当xml文件不符合xsd文件规则时,不是应该load失败吗? 再问怎么截获load失败信息啊??
    我是新手,这个问题很弱智,希望达人解答。万谢!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/9/13 14:58:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DTD/XML Schema 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/9 0:55:22

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

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