Re: [netmod] XPath node type tests

Robert Wilton <rwilton@cisco.com> Mon, 23 October 2017 10:06 UTC

Return-Path: <rwilton@cisco.com>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AB2B713F3A9 for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 03:06:03 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -14.501
X-Spam-Level:
X-Spam-Status: No, score=-14.501 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=cisco.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LS5OyML7l7eQ for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 03:06:01 -0700 (PDT)
Received: from aer-iport-3.cisco.com (aer-iport-3.cisco.com [173.38.203.53]) (using TLSv1.2 with cipher DHE-RSA-SEED-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2AD5813F3AB for <netmod@ietf.org>; Mon, 23 Oct 2017 03:06:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=5289; q=dns/txt; s=iport; t=1508753161; x=1509962761; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=J+/usBvPeoqIJc0M2DTGtaKmaqqX/tDkL8QPmLyq6+0=; b=cUu8DE577ZAIM8zJuggfDYXht/PU4QZKBtAJSWrjs2yl1CUL/gf3nsaF dFtDM9F4vN0n1yNnvF55rUwisqJXre97Sb8mo8ynWC1wvzEim606+2vM5 GZVBJOasq/rIIzQF3QihugY+g2INQmfQCy+F6LgpD2pxBOTSqK9xbpyAk M=;
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0D8AQA9vu1Z/xbLJq1cGQEBAQEBAQEBA?= =?us-ascii?q?QEBBwEBAQEBhEM5NSeDeosTkEd7lT6CEQoYC4RJTwKFChYBAgEBAQEBAQFrKIU?= =?us-ascii?q?eAQEBAwEBIRU2CxALDgoCAiYCAicwBgEMBgIBAYocEKtdgieLHQEBAQEBAQEBA?= =?us-ascii?q?QEBAQEBAQEBAQEBGQWBD4Ifg1eBaSmCTDWEb4MqgmEFkVCQFpR0i2yHNY4Zh2O?= =?us-ascii?q?BOSYMJYFbNCEIHRVJgmSEYD82i3oBAQE?=
X-IronPort-AV: E=Sophos;i="5.43,422,1503360000"; d="scan'208";a="656530738"
Received: from aer-iport-nat.cisco.com (HELO aer-core-4.cisco.com) ([173.38.203.22]) by aer-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2017 10:05:59 +0000
Received: from [10.63.23.64] (dhcp-ensft1-uk-vla370-10-63-23-64.cisco.com [10.63.23.64]) by aer-core-4.cisco.com (8.14.5/8.14.5) with ESMTP id v9NA5wEn025830; Mon, 23 Oct 2017 10:05:58 GMT
To: Martin Bjorklund <mbj@tail-f.com>, andy@yumaworks.com
Cc: netmod@ietf.org
References: <87h8utg7q8.fsf@nic.cz> <4b74f390-4817-9154-e427-cd879e0ceeb9@cisco.com> <CABCOCHROiHZ6ojdamjtto7gbC=WZ_NkaNP6D_pDDeGsGp=X7xQ@mail.gmail.com> <20171023.111041.247783860756995497.mbj@tail-f.com>
From: Robert Wilton <rwilton@cisco.com>
Message-ID: <93844bdb-dcd9-758e-f58a-4cad047d4fd7@cisco.com>
Date: Mon, 23 Oct 2017 11:05:58 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
MIME-Version: 1.0
In-Reply-To: <20171023.111041.247783860756995497.mbj@tail-f.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/FmpsE6Nr9j7qgMP4d2bX7lHaV2g>
Subject: Re: [netmod] XPath node type tests
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.22
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 23 Oct 2017 10:06:04 -0000


On 23/10/2017 10:10, Martin Bjorklund wrote:
> Andy Bierman <andy@yumaworks.com> wrote:
>> On Fri, Oct 20, 2017 at 9:24 AM, Robert Wilton <rwilton@cisco.com> wrote:
>>
>>> Hi Lada,
>>>
>>> Thanks for the explanation, that makes sense.
>>>
>>>
>>> On 20/10/2017 16:27, Ladislav Lhotka wrote:
>>>
>>>> Hi Rob,
>>>>
>>>> Robert Wilton <rwilton@cisco.com> writes:
>>>>
>>>> Hi,
>>>>> XPATH 1.0 defines the following three node-type tests:
>>>>>
>>>>> 1) comment()
>>>>> 2) processing-instruction(<opt arg>)
>>>>> 3) text()
>>>>>
>>>> For completeness, node() is the fourth one.
>>>>
>>>> My assumption is that a YANG tree doesn't contain any nodes of type
>>>>> 'comment' or 'processing-instruction' and hence these filters would
>>>>> never match any nodes.
>>>>>
>>>> Yes. FWIW, Yangson library raises NotSupported exception upon
>>>> encountering these.
>>>>
>> But a server or client should ignore PIs, not reject the XML.
>>
>> I think text() and node() are just filter tests.
>>
>>    /foo/*[text()] would return all the child nodes of /foo that are leaf or
>> leaf-list
>>
>> text() returns a boolean (0 or 1).  Do not use it for value testing:
> No.  text() will select the text node children of the context node.
This is presumably because text() is evaluated as "child::text()".

>
>>    /foo/*[text() = 'fred']  // wrong!
> This actually works.  text() selects all text nodes (just one for a
> leaf), and then that text node is compared to the string 'fred'.
For clarity, am I right in my interpretation that a leaf is not itself a 
text node, but instead a leaf is an element node that contains a direct 
child text node?

Presumably, it is only leaf and leaf-list element nodes that can have 
these direct child text nodes.

I can see how this make sense for a XML document, but it does feel a bit 
non intuitive for a YANG data tree, and it may be helpful if this is 
documented somewhat ...

   /foo/*[. = 'fred']  // correct

Presumably this test isn't quite the same, since child container and 
list nodes would also be included in the comparison (i.e. by 
concatenating all their descendant leaf values together into a single 
string), whereas the expression with the text() check will only include 
the values of direct child leaf and leaf-list nodes (as YANG is 
currently defined today).

Thanks,
Rob


>
>
>
> /martin
>
>
>
>
>>    /foo/*[. = 'fred']  // correct
>>
>> [7]    NodeTest    ::=    NameTest
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-NameTest>
>> | NodeType <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-NodeType> '('
>> ')'
>> | 'processing-instruction' '(' Literal
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Literal> ')'
>>
>>
>>>> However, it wasn't clear to me from reading 7950 or rfc6087bis-14
>>>>> whether text() matches anything.  In particular, does a YANG leaf node
>>>>> (except of type empty) always parent a text node that holds its value?
>>>>>
>>>> I believe this is how it should be interpreted. According to XPath 1.0
>>>> spec, comparisons like
>>>>
>>>>       xyz = 'foo'
>>>>
>>>> use string-value of xyz node, which is defined as the concatenation of
>>>> the string-values of all text node descendants of xyz.
>>>>
>>> Yes.  I don't think that I've ever come across for XPath usage in YANG
>>> where the "concatenation of the string-values of all text node descendants
>>> " is actually useful (particularly as the children nodes are likely to not
>>> be consistently ordered).
>>>
>>>
>>
>> I think text() and node() are just filter tests.
>>
>>    /foo/*[text()] would return all the child nodes of /foo that are leaf or
>> leaf-list
>>
>> text() returns a boolean (0 or 1).
>>
>>
>> [7]    NodeTest    ::=    NameTest
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-NameTest>
>> | NodeType <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-NodeType> '('
>> ')'
>> | 'processing-instruction' '(' Literal
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Literal> ')'
>>
>>
>>
>>
>> [38]    NodeType    ::=    'comment'
>> | 'text'
>> | 'processing-instruction'
>> | 'node'
>>
>>
>>
>>
>> The node test text() is true for any text node. For example, child::text() will
>> select the text node children of the context node. Similarly, the node test
>> comment() is true for any comment node, and the node test
>> processing-instruction() is true for any processing instruction. The
>> processing-instruction() test may have an argument that is Literal
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Literal>; in this case,
>> it is true for any processing instruction that has a name equal to the
>> value of the Literal
>> <https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Literal>.
>>
>>
>> Thanks,
>>> Rob
>>>
>>>
>>>
>>>> Lada
>>>>
>>>>
>> Andy
>>
>>
>>
>>> Thanks,
>>>>> Rob
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> netmod mailing list
>>>>> netmod@ietf.org
>>>>> https://www.ietf.org/mailman/listinfo/netmod
>>>>>
>>> _______________________________________________
>>> netmod mailing list
>>> netmod@ietf.org
>>> https://www.ietf.org/mailman/listinfo/netmod
>>>
> .
>