以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  xpath表达式和 nodeFromID不行  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=26535)


--  作者:lyshsd
--  发布时间:1/17/2006 7:08:00 PM

--  xpath表达式和 nodeFromID不行
本人是xml新手,诚向高手求教!

第一问:
按属性b条件查询selectNodes:
"/resource/script/sn/s[@b = \"00:10:04.893\“]"
这没有问题。

"/resource/script/sn/s[@b <= \"00:10:04.893\“"
"/resource/script/sn/s[@b < \"00:10:04.893\“"
则没有结果返回,这与文档内容不符。


第二问:nodeFromID函数用不起来。
schema定义了ID类型的属性,但nodeFromID不起作用。


--  作者:flyfoxs
--  发布时间:1/18/2006 1:02:00 PM

--  
可能大于,小于不能这样用吧?

“<” “<” “&”在XML里面都是保留的。

如果要用的话,可能xpath里面提供了大于,小于的函数。


--  作者:lyshsd
--  发布时间:1/18/2006 5:11:00 PM

--  
文档不用schema时,用函数ms:string-compare,
用 &lt;等皆不行!
<?xml version="1.0" encoding="UTF-8" ?>
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="script.xsd">
 <description>
  <titles v="friends-TOW The Ride Along">
   <title l="en" v="老友记 第五集" />
  </titles>
 </description>
 <script>
  <sn>
   <s id="a1" b="00:00:02.993" e="00:00:04.807" v="Okay. guys. listen.">
    <t l="zh" v="各位听好" />
   </s>
   <s id="a2" b="00:00:04.807" e="00:00:07.805" v="don't forget that tomorrow is the day that Emily gets married again.">
    <t l="zh" v="明天是爱米丽再婚的日子" />
   </s>
   <s id="a3" p="Monica" b="00:00:07.805" e="00:00:10.049" v="so whatever we do. just try to really keep Ross's mind off of it.">
    <t l="zh" v="我们要尽可能采取一切手段.转移罗斯的注意力" />
   </s>
</sn>
</script>
</resource>


schema:


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:annotation>
  <xsd:documentation xml:lang="en">
     schema of audio and video description for foreign language learning.
     copyright 2005. dufu. all rights reserved.
  </xsd:documentation>
 </xsd:annotation>
 
 <xsd:element name="resource" type="ResourceType" />
 <xsd:element name="comment" type="xsd:string" />
 <xsd:complexType name="ResourceType">
  <xsd:sequence>
   <xsd:element name="description" type="DescriptionType" />
   <xsd:element name="script" type="ScriptType" />
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="DescriptionType">
  <xsd:sequence>
   <xsd:element name="titles">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="title" minOccurs="0" maxOccurs="unbounded">
       <xsd:complexType>
        <xsd:attribute name="l" type="xsd:language" />
        <xsd:attribute name="v" type="xsd:string" />
       </xsd:complexType>
      </xsd:element>
     </xsd:sequence>
     <xsd:attribute name="v" type="xsd:string" />
    </xsd:complexType>
   </xsd:element>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="ScriptType">
  <xsd:sequence>
   <xsd:element name="sn" minOccurs="1" maxOccurs="unbounded" type="ScenarioType" />
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="ScenarioType">
  <xsd:sequence>
   <xsd:element name="s" minOccurs="1" maxOccurs="unbounded" type="SentenceType" />
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="SentenceType">
  <xsd:sequence>
   <xsd:element name="t" minOccurs="0" maxOccurs="unbounded">
    <xsd:complexType>
     <xsd:attribute name="l" type="xsd:language" />
     <xsd:attribute name="v" type="xsd:string" />
    </xsd:complexType>
   </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="id" type="xsd:ID" use="required" />
  <xsd:attribute name="p" type="xsd:string" use="optional" />
  <xsd:attribute name="b" type="xsd:time" use="required" />
  <xsd:attribute name="e" type="xsd:time" use="required" />
  <xsd:attribute name="l" type="xsd:language" use="optional" />
  <xsd:attribute name="v" type="xsd:string" use="required" />
 </xsd:complexType>
</xsd:schema>


--  作者:lyshsd
--  发布时间:1/18/2006 5:14:00 PM

--  
测试代码:

 CXMLHandler xml;  //自已写的一个类,已测试是正确的。
 xml.InitDomFromFile("d:\\dufusoft\\media\\Friends - 5x20 - TOW The Ride Along(NoSchema).xml") ;
 CString s;
 xml.GetNodeValue(_T("/resource/script/sn/s[@b = \"00:00:04.807\"]/@b"),s);   //此时有结果返回,但把=改为>=测返回空。


--  作者:lyshsd
--  发布时间:2/4/2006 5:15:00 PM

--  
使用xmlspy发现,根本原因是:1)xpath不支持xx:xx:xx.xxx类型的字符串,xpath2.0支持;2)必须在xpath1.0中,把time类型的值正确地在xpath中写出来。
--  作者:梦猫猫
--  发布时间:6/18/2006 4:59:00 PM

--  
XPATH里的<>符号,你用&lt;和&gt;代替试试
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
42.969ms