需要有关XPath谓词问题的帮助 [英] Need Help With XPath Predicate Issue

查看:69
本文介绍了需要有关XPath谓词问题的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;

我有一个带有选择谓词的XPath表达式
使用
从嵌套元素中获取一个人的姓名和ID XPathNavigator.Select方法.

这有效:
root/all_clients/client/client_name_and_ID [client_ID =``xxx'']

这也适用:
root/all_clients/client [client_name_and_ID/client_ID =``xxx'']/client_name_and_ID

当我将谓词带入下一个级别时,它将不起作用:
root/all_clients [客户端/客户端名称和ID/客户端ID ="xxx'']/客户端/客户端名称和ID

我没有进行任何过滤,但是整个过滤都没有.

这是由于ASP.NET中XPath固有的局限性吗?
还是我在做一些愚蠢的事情?

以下是相关XML文件的摘录:


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!!!

推荐答案

您做错了什么.您正在选择包含指定客户端ID的"all_clients"节点.由于所有客户端的列表都包含所有客户端ID,因此它当然会返回所有客户端列表.一旦有了所有客户端的列表,表达式的其余部分就会在该列表中选择"client_name_and_ID".因此,它将返回每个"client_name_and_ID".
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".


这篇关于需要有关XPath谓词问题的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆