On 23/10/2017 10:10, Martin Bjorklund wrote:
Andy Bierman <[email protected]> wrote:
On Fri, Oct 20, 2017 at 9:24 AM, Robert Wilton <[email protected]> wrote:

Hi Lada,

Thanks for the explanation, that makes sense.


On 20/10/2017 16:27, Ladislav Lhotka wrote:

Hi Rob,

Robert Wilton <[email protected]> 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
[email protected]
https://www.ietf.org/mailman/listinfo/netmod

_______________________________________________
netmod mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/netmod

.


_______________________________________________
netmod mailing list
[email protected]
https://www.ietf.org/mailman/listinfo/netmod

Reply via email to