2010-01-20 132 views
4

我会尝试非常明确地解释问题。我用户MicroSoftReportViewer在哪里我加载我的报告。但在加载之前,我想改变一些事情。在这里一切都很好。我想使用xpath,但是当我使用XMLDocument加载rdlc(xml)文件时,xpath表达式不起作用。唯一能工作的xpath是“\”女巫。我打开的记事本文件,看到的第一个XML节点使用这些模式使用xpath和rdlc报告

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" 
xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" 

我试图读取使用的XMLReader与XMLSchema的添加,但仍XPath不工作的文件。请让我非常感激得到代码的安宁,看看如何加载文件,使Xpath的作品。

最好的问候, 约尔丹

回答

5

只怕we'll需要看你的XPath语句可以肯定的,但我的猜测是与命名空间的问题。

未前缀的元件,其中,用于上述文献将其设置为
http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinitiondefault namespace

您的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); 

希望这会有所帮助。

+0

嗨,非常感谢答案就是我所需要的。它工作得很好。 – IordanTanev 2010-02-19 07:00:48