本文介绍了使用XPath和RDLC报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会尽量解释这个问题很清楚。我的用户MicroSoftReportViewer在那里我加载我的报告。但在加载之前我想在这里somethings.Till改变一切正常。我想使用XPath,但是当我使用的XMLDocument加载RDLC(XML)文件中的XPath表达式不起作用。这项工作是唯一的XPath\女巫得到根。我打开的记事本文件,看到第一个XML节点使用这些模式

i will try to explain the problem very clear. I user MicroSoftReportViewer where i load my report. But before loading it i want to change somethings.Till here everything is ok. I want to use xpath but when i load the rdlc( xml ) file using XMLDocument the xpath expression does not work. The only xpath that work is "\" witch gets root. I opened the file with notepad and saw that the first xml node uses these schemas

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

我试图读取使用的XMLReader与XML模式添加,但仍XPath不工作的文件。请我将是非常巨大的感谢得到的代码和平来看看如何加载该文件,以便XPath的工作原理。

I tried to read the file using XMLReader with XMLSchema added but still xpath does not work. Please i will be very great grateful to get peace of code to see how to load the file so xpath works.

最好的问候,
约尔丹

Best Regards,Iordan

推荐答案

只怕我们就会需要看你的XPath语句可以肯定的,但我的猜测是命名空间的问题。

I´m afraid we´ll need to see your XPath statement to be sure, but my guess is an issue with namespaces.

这是没有前缀的元素是在默认命名空间这对于上述文件将其设置为结果

The elements that are not prefixed are in the default namespace which for the above document sets it to
http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition.

您XPath查询现在需要在查询这些命名空间。所以,一个的selectSingleNode( / elementnameicanseeinnotepad )不会给你任何东西。

You XPath queries now need to include these namespaces in the queries. So, an selectSingleNode(/elementnameicanseeinnotepad) will not give you anything.

要添加的命名空间中查询您必须使用的XmlNamespaceManager 类(或使用XPath的详细语法,我不推荐)。

To add the namespaces in the query you will have to use the XmlNamespaceManager class (or use the verbose syntax of XPath which i don´t recommend).

// 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 );



希望这有助于。

Hope this helps.

这篇关于使用XPath和RDLC报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:48
查看更多