About XPathReader

  • Thread starter Thread starter Ma Ning
  • Start date Start date
M

Ma Ning

Hi All:
I have read a article about XPathReader on Alex Yakhnin's blogs.I tested
the sample with my own XML file.It like this:
<Table>
<Name>
wolf
</Name>
</Table>
I used it "\Table\[Name='wolf']",but the project throw a Execpiton.
Thanks.
 
First of all you really should include the exception details and the line on
which it is thrown. Otherwise this is pointless. Second, shouldn't you be
using forward slash?
"/Table/[Name='wolf']"
 
Thanks,Alex.This is my code:

GotDotNet.XPath.XPathCollection xc = new XPathCollection();
xc.Add("//Table/[Name='wolf']");
XmlTextReader reader = new XmlTextReader("PocketTrip.xml");

and the Excepiton is:
Expression //Table/[Name='wolf'] must evaluate to a node-set.


Alex Feinman said:
First of all you really should include the exception details and the line
on which it is thrown. Otherwise this is pointless. Second, shouldn't you
be using forward slash?
"/Table/[Name='wolf']"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Ma Ning said:
Hi All:
I have read a article about XPathReader on Alex Yakhnin's blogs.I tested
the sample with my own XML file.It like this:
<Table>
<Name>
wolf
</Name>
</Table>
I used it "\Table\[Name='wolf']",but the project throw a Execpiton.
Thanks.
 
Well it should look like this:

//Table[Name='wolf']

But this query type is not supported by this XPathReader it always
throws exception "Can't get the child value". As a workaround I can
suggest you to move Name to a Table tag as the attribute and rewrite
query in such manner:

//Table[@Name='wolf']

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Ma said:
Thanks,Alex.This is my code:

GotDotNet.XPath.XPathCollection xc = new XPathCollection();
xc.Add("//Table/[Name='wolf']");
XmlTextReader reader = new XmlTextReader("PocketTrip.xml");

and the Excepiton is:
Expression //Table/[Name='wolf'] must evaluate to a node-set.


First of all you really should include the exception details and the line
on which it is thrown. Otherwise this is pointless. Second, shouldn't you
be using forward slash?
"/Table/[Name='wolf']"

--
Alex Feinman
---
Visit http://www.opennetcf.org
Hi All:
I have read a article about XPathReader on Alex Yakhnin's blogs.I tested
the sample with my own XML file.It like this:
<Table>
<Name>
wolf
</Name>
</Table>
I used it "\Table\[Name='wolf']",but the project throw a Execpiton.
Thanks.
 
Back
Top