all groups > sql server reporting services > february 2007 >
You're in the

sql server reporting services

group:

unable to parse RDLC with xpath



unable to parse RDLC with xpath victor.cassel NO[at]SPAM gmail.com
2/21/2007 6:25:48 AM
sql server reporting services: First, I add a new report in Visual Studio 2005 (SP1) to get an empty
RDLC file.

Then, i try to get a reference to a node in this xml file using either
SelectSingleNode in System.Xml namespace or the more advance
SelectSingleNode-function in the System.Xml.Path namespace. But the
function returns null because it does not find a match.

If have tried to use a XMLNameSpaceManager without success.

However, when i remove the default namespace from the rdl-definition
the call succeeds!


string filename = @"C:\demo\aa.xml"; // this is an report
file...

XmlDocument document = new XmlDocument();
document.Load(filename);

XPathNavigator nav = document.CreateNavigator();
nav = nav.SelectSingleNode("//Report/Body/ReportItems/
Rectangle[@Name='rctPage3']/ReportItems");


SelectSingleNode("//") works but not SelectSingleNode("//Report") for
example.

I have two files that look identical in notepad, but differ somewhere
in binary, they are utf8-encoded (allthough report files are ansi-
encoded as of default??) aa.xml and bb.xml.

One is working but not the other...???

All help is appreciated.
/Victor Cassel
Re: unable to parse RDLC with xpath victor.cassel NO[at]SPAM gmail.com
2/22/2007 5:21:13 AM
[quoted text, click to view]

Here is a shorter stating of the problem.

Can anyone show me a code example (vs 2005) of how to parse the
simplest possible RDLC with an xpath query with SelectSingleNode?

There seems to be some problem with the namespaces in the RDLC-files.

//victor
Re: unable to parse RDLC with xpath victor.cassel NO[at]SPAM gmail.com
3/1/2007 3:46:23 AM
[quoted text, click to view]

I found the answer myself.

Apparently, the default namespace does not work with the namespace
manager, so you have to give the default name space a name, for
example ns.

Then your xpath questions work, if you write them like this:

XmlNamespaceManager ns =3D new
XmlNamespaceManager(pg1.NameTable);
ns.AddNamespace("ns", "http://schemas.microsoft.com/sqlserver/
reporting/2005/01/reportdefinition");
ns.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/
reporting/reportdesigner");

string source =3D "//ns:Report/ns:Body/ns:ReportItems/
ns:Rectangle[@Name=3D'rctPage']/ns:ReportItems";

MessageBox.Show(pg1.SelectSingleNode(source, ns).InnerXml);

Notice that you should not add the namespace identifier for
attributes, see @Name above. Very strange, but it works.

/Victor

AddThis Social Bookmark Button