2010-01-20 124 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