[quoted text, click to view] On 22 Feb, 14:21, victor.cas...@gmail.com wrote:
> On 21 Feb, 15:25,victor.cas...@gmail.com wrote:
>
>
>
>
>
> > 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 =3D @"C:\demo\aa.xml"; // this is an report
> > file...
>
> > XmlDocument document =3D new XmlDocument();
> > document.Load(filename);
>
> > XPathNavigator nav =3D document.CreateNavigator();
> > nav =3D nav.SelectSingleNode("//Report/Body/ReportItems/
> > Rectangle[@Name=3D'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.
> > /VictorCassel
>
> 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- D=F6lj citerad text -
>
> - Visa citerad text -
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