xml文件
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <log>
    <Date>2003-01-02T11:30:00-05:00</Date>
    <user>[email protected]</user>
  </log>
</root>
我从microsoft网站的how to上抄了一个例子,稍改了一下
          XmlDocument oxmldoc = new XmlDocument();
            oxmldoc.Load("test.xml");            XPathNavigator oXPathNav;
            oXPathNav = oxmldoc.CreateNavigator();            XPathExpression Expr;
            Expr = oXPathNav.Compile("//log[Date=xs:dateTime(\"2003-01-02T11:30:00-05:00\")]");            XmlNamespaceManager oxmlNSManager = new XmlNamespaceManager(oXPathNav.NameTable);
            oxmlNSManager.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");            Expr.SetContext(oxmlNSManager);            XPathNodeIterator iterator = oXPathNav.Select(Expr);
执行到Expr.SetContext(oxmlNSManager);
报错“由于存在未知的函数,此查询需要 XsltContext。”
哪位老大能指点一下吗

解决方案 »

  1.   

    1,ns写错了
    2,xpath不对
    正确的如下            XPathExpression Expr;
                Expr = oXPathNav.Compile("//log[Date='2003-01-02T11:30:00-05:00']");            XmlNamespaceManager oxmlNSManager = new XmlNamespaceManager(oXPathNav.NameTable);
                oxmlNSManager.AddNamespace("xs", "http://www.w3.org/2001/XLSchema");
      

  2.   

    感谢您的回答,首先我写这个例子就是想实验C#对xpath2.0中时间函数的支持另外,我不知道("xs", "http://www.w3.org/2001/XLSchema");
    引子何处因为我不太懂xml所以一般都是东抄一段,西抄一段
    ("xs", "http://www.w3.org/2001/XLSchema");
    我写的那个ns是这里抄的
    http://www.w3.org/TR/xquery-operators/#namespace-terminology
    The URIs of the namespaces and the default prefixes associated with them are:http://www.w3.org/2001/XMLSchema for constructors -- associated with xs.http://www.w3.org/2005/xpath-functions for functions -- associated with fn.http://www.w3.org/2005/xqt-errors -- associated with err.
      

  3.   

    最后还是放弃了,直接用 altova的东西
    再一次证明,微软二