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。”
哪位老大能指点一下吗
<?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。”
哪位老大能指点一下吗
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");
引子何处因为我不太懂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.
再一次证明,微软二