恐怕我们需要查看您的 XPath 语句才能确定,但我的猜测是名称空间的问题。
没有前缀的元素default namespace
在上述文档的 which 中设置为
http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition。
您的 XPath 查询现在需要在查询中包含这些名称空间。所以,一个 selectSingleNode( /elementnameicanseeinnotepad
) 不会给你任何东西。
要在查询中添加命名空间,您必须使用XmlNamespaceManager
类(或使用我不推荐的 XPath 的详细语法)。
// get an instance
XmlNamespaceManager xMngr = new XmlNamespaceManager();
// associate the prefix ´def´ with the namespace-uri from the xml document we loaded
xMngr.AddNamespace( `def´, http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition);
// associate the prefix ´rd´ (same as used in document) with the namespace-uri from the xml document we loaded
xMngr.AddNamespace( `rd´, http://schemas.microsoft.com/SQLServer/reporting/reportdesigner);
// use the prefix(s) in the XPath query
xDoc.DocumentElement.SelectSingleNode(´/def:elementnameiseeinnotepad´, xMngr );
希望这可以帮助。