使用xpath和rdlc报告

Ior*_*nev 4 c# xml rdlc

我会尽力解释这个问题.我使用MicroSoftReportViewer加载我的报告.但在加载之前我想改变一些事情.到这里一切都好.我想使用xpath但是当我使用XMLDocument加载rdlc(xml)文件时,xpath表达式不起作用.唯一有效的xpath是"\"女巫得到了根.我用记事本打开文件,看到第一个xml节点使用这些模式

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" 
xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
Run Code Online (Sandbox Code Playgroud)

我尝试使用添加了XMLSchema的XMLReader读取文件但仍然无法使用xpath.请非常感谢获得代码的和平,以了解如何加载文件,以便xpath工作.

最诚挚的问候,Iordan

Mar*_*mit 5

我担心我们需要确定你的XPath声明,但我的猜测是命名空间的问题.

未加前缀的元素default namespace在上面的文档中将其设置为
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 );
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.