tags:

views:

254

answers:

1

Hi, 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"

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

+2  A: 

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´.

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

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,

Marvin Smit
Hi, thanks a lot for the answer is just what i needed.It work fine.
IordanTanev