比如我有这样一个Schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Staff" xmlns="" xmlns:mstns="http://tempuri.org/Staff.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="Staffs">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ID" type="xs:int" />
        <xs:element name="Name" type="xs:string" />
        <xs:element name="Age" type="xs:int" minOccurs="0" />
        <xs:element name="Sex" type="xs:string" minOccurs="0" />
        <xs:element name="Job" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>我想通过Name模糊查询数据,写了一个模板:
<?xml version="1.0" encoding="utf-8" ?><ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
  <sql:header>
    <sql:param name="Name"/>
  </sql:header>
  
    <sql:xpath-query mapping-schema="Staff.xsd">
    /Staffs[Name=$Name]<!-- 这个地方该怎么写 如果写SQL 会写 Name like '%'+@Name+'%' 用XPath该写什么呢?-->  </sql:xpath-query>
</ROOT>

解决方案 »

  1.   

    zjcxc(邹建) 老大都没有用过,LZ问题强啊
      

  2.   

    我几年前在win2k上做过,不过仅仅是引用HTTP查询生成的结果用作数据.
    昨天看到楼主这个题目时,我就想测试,配置SQLXML时老是有问题.
    开始用URL查询时老是提示页面不存在, 我想到当IIS中禁用ASP.NET扩展时,浏览aspx页面也这样提示,就将IIS中所有扩展打开,再看时,提示mssql isapi虚拟根配置有误之类的提示,实在找不出问题出在哪,苦于没有办法测试,所以没有回贴.如果哪位朋友知道问题所在,还请赐教.今天看到楼主后面这个回贴,我想你想的是对某个节点属性值进行模糊查询吧
    如果是这个要求,楼主可以试试XPath里的contains函数, 有点像SQL中的CHARINDEX或C系的indexOf函数,只不过有点区别,contains返回逻辑值./Staffs[contains(Name,$Name)]
    不知道写的对不对,没有办法测试.仅供参考. 楼主也出来后也请告知正确的写法.
      

  3.   

    哭死,SQLXML不支持contains:Unsupported Functionality
    The following table shows the features of the XPath language that are not implemented in SQL Server 2000.Feature :
    String functions 
    Item:
    string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize(), translate()
      

  4.   

    先把XML变成Dataset然后用 dataview的rowfilter的方法来找
      

  5.   

    如果写SQL 会写 Name like '%'+@Name+'%' 用XPath该写什么呢?-->在xpath 里面用的时候可以是:
    _XPathContent=" contains(child::ConsulationName,\"" + ConsulationName.ToString()+ "\")" ;
    俺是这样实现了在.NET中对XML数据进行查询
    contains 是XML的内部函数,表示包含了某些内容
    上面那一行的意思是:
    在节点 ConsulationName 中包含了 m_ConasulationName这个参数内容的节点
    同理要用在XSLT文件中也是一样的
      

  6.   

    <?MSSQLError HResult="0x80004005" Source="Microsoft XML Extensions to SQL Server" Description="XPath: 不支持 contains() 函数"?> SQLXML帮助文档里说的很清楚:
    Unsupported Functionality
    The following table shows the features of the XPath language that are not implemented in SQL Server 2000.Feature :
    String functions 
    Item:
    string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize(), translate()我用的是SQLXML3.0+SQL Server 2000 sp4