Re: [netmod] XPath node type tests

Martin Bjorklund <mbj@tail-f.com> Mon, 23 October 2017 09:12 UTC

Return-Path: <mbj@tail-f.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 AEB2413F3A0 for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 02:12:12 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.901
X-Spam-Level:
X-Spam-Status: No, score=-1.901 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
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 ENRsUa0mvAcl for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 02:12:10 -0700 (PDT)
Received: from mail.tail-f.com (mail.tail-f.com [46.21.102.45]) by ietfa.amsl.com (Postfix) with ESMTP id 6DD2613F398 for <netmod@ietf.org>; Mon, 23 Oct 2017 02:12:09 -0700 (PDT)
Received: from localhost (unknown [173.38.220.41]) by mail.tail-f.com (Postfix) with ESMTPSA id 1CF541AE012C; Mon, 23 Oct 2017 11:12:07 +0200 (CEST)
Date: Mon, 23 Oct 2017 11:10:41 +0200 (CEST)
Message-Id: <20171023.111041.247783860756995497.mbj@tail-f.com>
To: andy@yumaworks.com
Cc: rwilton@cisco.com, netmod@ietf.org
From: Martin Bjorklund <mbj@tail-f.com>
In-Reply-To: <CABCOCHROiHZ6ojdamjtto7gbC=WZ_NkaNP6D_pDDeGsGp=X7xQ@mail.gmail.com>
References: <87h8utg7q8.fsf@nic.cz> <4b74f390-4817-9154-e427-cd879e0ceeb9@cisco.com> <CABCOCHROiHZ6ojdamjtto7gbC=WZ_NkaNP6D_pDDeGsGp=X7xQ@mail.gmail.com>
X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/YydQ_Yb2wZJKYsCZFqUWoyf1MJk>
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 09:12:13 -0000

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.

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



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