Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.Evaluate xpath statement

Status
Not open for further replies.

euntair

Programmer
Sep 13, 2007
53
US
I tested /project/pages/page[@completed='n'][not(text())=''] at with success but the xpath expression below doesn't work in C#. How do I re-write the xpath statement so I can use .Evaluate to return a empty node-set in C#?

string xpath = "/project/pages/page[@completed='n'][not(text())='']";
bool not_finished = (bool)xd.CreateNavigator().Evaluate(xpath);

<project>
<pages>
<page id="1" completed="y">one</page>
<page id="2" completed="y">two</page>
<page id="3" completed="y">three</page>
<page id="4" completed="y">four</page>
<page id="5" completed="y">five</page>
<page id="6" completed="y">six</page>
</pages>
</project>
 
To verify empty node set return, you use the Count property exposed by XPathNodeIterator. But if you use Evaluate(), you need to explicitly cast it to it, in contrast to using Select(). And then, the return of Count be integer and you need to further convert it to Boolean. The combined considerations result in the form like this.

>bool not_finished = (bool)xd.CreateNavigator().Evaluate(xpath);
[tt]bool not_finished=Convert.ToBoolean(((XPathNodeIterator)xd.CreateNavigator().Evaluate(xpath)).Count);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top