【问题标题】:Using xpath and rdlc report使用 xpath 和 rdlc 报告
【发布时间】:2010-01-20 07:37:22
【问题描述】:

我会尽量把问题解释清楚。我在加载报告的地方使用 MicroSoftReportViewer。但在加载它之前我想改变一些东西。直到这里一切都好。我想使用 xpath,但是当我使用 XMLDocument 加载 rdlc( xml ) 文件时,xpath 表达式不起作用。唯一有效的 xpath 是 "\" 女巫获得 root。我用记事本打开文件,发现第一个 xml 节点使用了这些模式

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

我尝试使用添加了 XMLSchema 的 XMLReader 读取文件,但 xpath 仍然不起作用。请让我非常感谢您获得和平代码以查看如何加载文件以便 xpath 工作。

最好的问候, 约旦

【问题讨论】:

    标签: c# xml rdlc


    【解决方案1】:

    恐怕我们需要查看您的 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 );
    

    希望这会有所帮助。

    【讨论】:

    • 嗨,非常感谢您的回答正是我所需要的。它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 2012-01-24
    • 2019-01-08
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多