Re: [netmod] XPath node type tests

Andy Bierman <andy@yumaworks.com> Fri, 20 October 2017 16:55 UTC

Return-Path: <andy@yumaworks.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 8B68E1342E3 for <netmod@ietfa.amsl.com>; Fri, 20 Oct 2017 09:55:32 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.599
X-Spam-Level:
X-Spam-Status: No, score=-2.599 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=yumaworks-com.20150623.gappssmtp.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 HNjngvNtdwC9 for <netmod@ietfa.amsl.com>; Fri, 20 Oct 2017 09:55:30 -0700 (PDT)
Received: from mail-lf0-x235.google.com (mail-lf0-x235.google.com [IPv6:2a00:1450:4010:c07::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9DC9413235C for <netmod@ietf.org>; Fri, 20 Oct 2017 09:55:29 -0700 (PDT)
Received: by mail-lf0-x235.google.com with SMTP id r129so13872002lff.8 for <netmod@ietf.org>; Fri, 20 Oct 2017 09:55:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yumaworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1J7j0GfsqnYvMGVuLoqFEmS5bZnPmw+6UXHbblrsgoc=; b=La5VunVXfhG8jCk7OC/5U4TotJweQAMQSobsTagEvxE9rO/+6HYlBqMLgnRmHhDCo3 8MouGtQBGnR+zmbrIjcfswPNgtIwMfOxP/zQ/tA1+pFw5NOB81T7I/xWG6A3qQeEmnE6 MZwPOMFHH2gTOflqvPvs7IH3gE3nFc/Da35cercR/LUPmKYysVyWuUnj+Qm985oreFYM 4HO9Q76jiAvVql4N5OB1m1sSCE5fEdESTzAIFFIrSaXdVZFD+NGqfJns0dWxqY4F6QvZ nxInWC9tXQzvW60gVt3Y71RMdgDB4GidSRawMZ9UbDNG4kq9++1FSURcml/7xCZI5T3x iL4w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=1J7j0GfsqnYvMGVuLoqFEmS5bZnPmw+6UXHbblrsgoc=; b=P3rY/ndD9bRw6/OTcGzEjU4V9hQ6ewIknEfXfyQe3GGQJxe4teC3LGxgo84rrlIz8L NTWdgEOoKmhfg+3EkZotOJh7BDRh8IlwD/aUNaHfSwrzd871sBjcQT99xW0NnmrPQiZ/ AQs23IfAjSax9LsEnB4N0RxwENDveN5M2z8EereSY1eHo7SkvqUO1r1YSxqE84G5QOpd nJTqj73MKavUIiP1pQQiZfHthY0MqJTd5A+QUT/3NcSN9gVdFQ/xO0QqvHGlGcT24iUo a5JVmWZwI1muY5BtB3TCEF+wwyppkXyVhqk0QgGA2N/Dyq698WwEie/XDW9KokGReOzi 2ndQ==
X-Gm-Message-State: AMCzsaUVRbaRCURKMbmSlPyvZQVvxmoMdlgPcxUgC7afrqjw7Hg2UEy0 KB7hLqra7tsAG8L+k+nxu5N5Y6+ipOTMqxPH13/4O/Ao
X-Google-Smtp-Source: ABhQp+QoSTaNYVTF3CjTniYoriYb5D6mNE3OlhkP9VkjnpaSisBUCHxjWSUiVjzly4/OVeMj+LajmCcgYdbqCEfdLVw=
X-Received: by 10.46.83.25 with SMTP id h25mr2389912ljb.158.1508518527945; Fri, 20 Oct 2017 09:55:27 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.25.150.198 with HTTP; Fri, 20 Oct 2017 09:55:27 -0700 (PDT)
In-Reply-To: <4b74f390-4817-9154-e427-cd879e0ceeb9@cisco.com>
References: <aba8fca4-4cc7-ee66-6adf-baac5485b12a@cisco.com> <87h8utg7q8.fsf@nic.cz> <4b74f390-4817-9154-e427-cd879e0ceeb9@cisco.com>
From: Andy Bierman <andy@yumaworks.com>
Date: Fri, 20 Oct 2017 09:55:27 -0700
Message-ID: <CABCOCHROiHZ6ojdamjtto7gbC=WZ_NkaNP6D_pDDeGsGp=X7xQ@mail.gmail.com>
To: Robert Wilton <rwilton@cisco.com>
Cc: "netmod@ietf.org" <netmod@ietf.org>
Content-Type: multipart/alternative; boundary="f40304360142fee11c055bfd560b"
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/vqNvTey4eN9y0uSAncwuqsdtHBc>
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: Fri, 20 Oct 2017 16:55:32 -0000

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:

  /foo/*[text() = 'fred']  // wrong!

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