Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all;

I've got an XPath expression with a predicate that selects
a person's name and ID from within a nested element, using
the XPathNavigator.Select method.

This works:
root/all_clients/client/client_name_and_ID[client_ID = 'xxx']

This also works:
root/all_clients/client[client_name_and_ID/client_ID = 'xxx']/client_name_and_ID

When I take the predicate to the next level, it does not work:
root/all_clients[client/client_name_and_ID/client_ID = 'xxx']/client/client_name_and_ID

I do not get any filtering, but the entire set.

Is this due to a limitation inherent within XPath, within ASP.NET,
or am I doing something stupid?

What follows is a snippet from the relevant XML file:


<<pre lang="xml">?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="file:///n:\Projects\XML\Medical\Example_01.xsd">
    <all_clients>
        <client>
            <client_name_and_ID>
                <first_name>Fred</first_name>
                <middle_name>James</middle_name>
                <last_name>Bowman</last_name>
                <client_ID>1</client_ID>
            </client_name_and_ID>
        </client>
        <client>
            <client_name_and_ID>
                <first_name>Mark</first_name>
                <middle_name>David</middle_name>
                <last_name>Colder</last_name>
                <client_ID>2</client_ID>
            </client_name_and_ID>
        </client>
        <client>
            <client_name_and_ID>
                <first_name>Joe</first_name>
                <last_name>Lewis</last_name>
                <client_ID>3</client_ID>
            </client_name_and_ID>
        </client>
        <client>
            <client_name_and_ID>
                <first_name>Sam</first_name>
                <last_name>Plank</last_name>
                <client_ID>4</client_ID>
            </client_name_and_ID>
        </client>
    </all_clients>
</root>




THANKS!!!
Posted

1 solution

You are doing something incorrectly. You are selecting the "all_clients" node that contains the specified client ID. Since the list of all clients contains all the client ID's, it will of course return the all clients list. Once you have that list of all clients, the rest of your expression selects the "client_name_and_ID" within that list. Hence, it returns every "client_name_and_ID".
 
Share this answer
 
Comments
wylbur 11-Feb-11 14:07pm    
So i was - indeed - doing something stupid.

Thanks for setting me straight.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900