Re: [netmod] XPath node type tests
Ladislav Lhotka <lhotka@nic.cz> Mon, 23 October 2017 11:32 UTC
Return-Path: <lhotka@nic.cz>
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 3BCE713F3C7 for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 04:32:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7
X-Spam-Level:
X-Spam-Status: No, score=-7 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] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nic.cz
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 JhctRmxRA7fX for <netmod@ietfa.amsl.com>; Mon, 23 Oct 2017 04:32:38 -0700 (PDT)
Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id D7FBB13F3C1 for <netmod@ietf.org>; Mon, 23 Oct 2017 04:32:37 -0700 (PDT)
Received: from [IPv6:2a01:5e0:29:ffff:29c8:f93b:f52b:6626] (unknown [IPv6:2a01:5e0:29:ffff:29c8:f93b:f52b:6626]) by mail.nic.cz (Postfix) with ESMTPSA id 2F17C60114; Mon, 23 Oct 2017 13:32:35 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1508758355; bh=PAScexyxsO0daiz4BmOzFrRR59JTcv6AxTClFRBf9es=; h=From:Date:To; b=wSrzpZo/Mj4v2k2hdkzGZbYkRh7N911pdr2pAHJbOOmLJWfToHGjf3xu539MEdpk0 PgKkaXLgCj0r4Ry0ULNjF7fglnFuJ/vCObZJJeJO1pKmJKG8GeXw4LVaT0B/9mixKA zif+VP0osj0SFjzjMrP6llUUJya+5dnjb3z+9XJY=
Content-Type: text/plain; charset="us-ascii"
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
From: Ladislav Lhotka <lhotka@nic.cz>
In-Reply-To: <20171023.123734.1274882060625273119.mbj@tail-f.com>
Date: Mon, 23 Oct 2017 13:33:12 +0200
Cc: Robert Wilton <rwilton@cisco.com>, netmod@ietf.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <EF2E5EFA-514B-47CC-86EF-59054442C208@nic.cz>
References: <CABCOCHROiHZ6ojdamjtto7gbC=WZ_NkaNP6D_pDDeGsGp=X7xQ@mail.gmail.com> <20171023.111041.247783860756995497.mbj@tail-f.com> <93844bdb-dcd9-758e-f58a-4cad047d4fd7@cisco.com> <20171023.123734.1274882060625273119.mbj@tail-f.com>
To: Martin Björklund <mbj@tail-f.com>
X-Mailer: Apple Mail (2.3273)
X-Virus-Scanned: clamav-milter 0.99.2 at mail
X-Virus-Status: Clean
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/F6dclhBG3L4qrL6kATJToFhApVo>
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 11:32:40 -0000
> On 23 Oct 2017, at 12:37, Martin Bjorklund <mbj@tail-f.com> wrote: > > Robert Wilton <rwilton@cisco.com> wrote: >> >> >> 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()". > > Yes. > >>>> /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? > > Yes. In principle, there could be multiple text nodes (in XML processing this is quite common). Lada > >> Presumably, it is only leaf and leaf-list element nodes that can have >> these direct child text nodes. > > Yes. > >> I can see how this make sense for a XML document, but it does feel a >> bit non intuitive for a YANG data tree > > Maybe, but since we use XPath, we need to conform to the data model > used by XPath (see section 5 of the xpath spec). > >> and it may be helpful if this >> is documented somewhat ... > > RFC 7950 refers to the data model of XPath (See section 6.4 of RFC > 7950), but I agree that it could have had more text. Specifically, it > could have stated how nodes are mapped to elements, that only > leaf/leaf-list have text nodes; that annotations are mapped to > attribute nodes (ok, not really in 7950...); that there are no > processing-instruction and comment nodes. > >> >> /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). > > Yes. > > > /martin > > _______________________________________________ > netmod mailing list > netmod@ietf.org > https://www.ietf.org/mailman/listinfo/netmod -- Ladislav Lhotka Head, CZ.NIC Labs PGP Key ID: 0xB8F92B08A9F76C67
- [netmod] XPath node type tests Robert Wilton
- Re: [netmod] XPath node type tests Ladislav Lhotka
- Re: [netmod] XPath node type tests Robert Wilton
- Re: [netmod] XPath node type tests Andy Bierman
- Re: [netmod] XPath node type tests Martin Bjorklund
- Re: [netmod] XPath node type tests Robert Wilton
- Re: [netmod] XPath node type tests Martin Bjorklund
- Re: [netmod] XPath node type tests Ladislav Lhotka
- Re: [netmod] XPath node type tests Martin Bjorklund
- Re: [netmod] XPath node type tests Phil Shafer