First I did see this but it did not seem to help XPath SelectNodes in .NET
I am trying to read a SSRS report defination.
ReportingService report = new ReportingService();
report.Credentials = System.Net.CredentialCache.DefaultCredentials;
string x = new System.Text.UTF8Encoding().GetString(
report.GetReportDefinition(ReportName));
//Remove a Character at the beginning of the document -- Char 65279
x = x.Replace(x.Substring(0, 1), "");
XmlDocument xml = new XmlDocument();
XmlNamespaceManager ns = new XmlNamespaceManager(xml.NameTable);
// This appears to be a reserved default?
//ns.AddNamespace("xmlns","http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
ns.AddNamespace("xmlns:rd","http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
xml.LoadXml(x);
Now I am looking for the Query node which should be under
Report
...
DataSets
DataSet
Query
Now if I look at some variables
xml.Name = "#document"
xml.DocumentElement.Name = "Report"
xml.DocumentElement.ChildNodes[12].Name = "DataSets"
xml.DocumentElement.ChildNodes[12].ChildNodes[0].Name = "DataSet"
xml.DocumentElement.ChildNodes[12].ChildNodes[0].ChildNodes[1].Name = "Query"
But the problem is trying a couple of things I can not get to this DataSets Node or any subnodes. Example
xml.DocumentElement.SelectNodes(".//DataSets",ns);
xml.DocumentElement.SelectNodes("DataSets",ns);
xml.SelectSingleNode("//Report/DataSets",ns);
xml.SelectSingleNode("//Query",ns);
Both return null what am I doing wrong.
Edited using driis advice