C# 提供了 XmlNamespaceManager,但仍然得到“需要命名空间管理器或 XsltContext”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2311526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XmlNamespaceManager provided, but still get "Namespace Manager or XsltContext needed"
提问by Hiyasat
i am trying to read the following and select a node in it
我正在尝试阅读以下内容并在其中选择一个节点
<ns1:OrderInfo xmlns:ns1="http://xxxxxx Some URL XXXX">
<pricing someAttrHere>
<childnodes>
</pricing>
</ns1:OrderInfo>
.
.
XmlDocument document = new XmlDocument();
document.Load(Server.MapPath("order.xml"));
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("ns1", "http://xxxxxx Some URL XXXX");
query = "/ns1:OrderInfo/pricing";
XmlNodeList nodeList = document.SelectNodes(query);
but it always give "Namespace Manager or XsltContext needed"
但它总是给出“需要命名空间管理器或 XsltContext”
as you can see above i add namespace using XmlNamespaceManager and still give the error please any help
正如你在上面看到的,我使用 XmlNamespaceManager 添加命名空间,但仍然给出错误,请任何帮助
采纳答案by Mark Seemann
You need to useyour XmlNamespaceManager as well:
您还需要使用XmlNamespaceManager:
XmlNodeList nodeList = document.SelectNodes(query, manager);