libyang-XPath Addressing

libyang中的XPath评估主要应用于当和必须条件的模式。XPath 1.0的实现允许使用类似when或must的表达式。路径用于标识augment目标、leafref目标等。XPath遵循JSON规范,包括绝对路径和相对路径的处理。lyd_find_xpath()和lys_find_xpath()等功能用于处理简化版XPath,这些路径基于节点祖先在模式中的位置来识别特定节点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Internally, XPath evaluation is performed on when and must conditions in the schema. For that almost a full XPath 1.0 evaluator was implemented. In YANG models you can also find paths identifying augment targets, leafref targets, and trivial paths in choice default and unique statements argument. The exact format of all those paths can be found in the relevant RFCs. Further will only be discussed paths that are used directly in libyang API functions.

XPath

Generally, any xpath argument expects an expression similar to when or must as the same evaluator is used. As for the format of any prefixes, the standardized JSON (RFC 7951) was used. Summarized, xpath follows these conventions:

  • full XPath can be used, but only data nodes (node sets) will always be returned,
  • as per the specification, prefixes are actually module names,
  • also in the specification, for absolute paths, the first (leftmost) node MUST have a prefix,
  • for relative paths, you specify the context node, which then acts as a parent for the first node in the path,
  • nodes always inherit their module (prefix) from their parent node so whenever a node is from a different module than its parent, it MUST have a prefix,
  • nodes from the same module as their parent MUST NOT have a prefix,
  • note that non-data nodes/schema-only node (choice, case, uses, input, output) are skipped and MUST not be included in the path.

Functions List

Path

The term path is used when a simplified (subset of) XPath is expected. Path is always a valid XPath but not the other way around. In short, paths only identify a specific (set of) nodes based on their ancestors in the schema. Predicates are allowed the same as for an instance-identifier. Specifically, key values of a list, leaf-list value, or position of lists without keys can be used.

Examples

  • get list instance with key1 of value 1 and key2 of value 2 (this can return more list instances if there are more keys than key1 and key2)
    /module-name:container/list[key1='1'][key2='2']
    
  • get leaf-list instance with the value val
    /module-name:container/leaf-list[.='val']
    
  • get 3rd list-without-keys instance with no keys defined
    /module-name:container/list-without-keys[3]
    
  • get aug-list with aug-list-key, which was added to module-name from an augment module augment-module
    /module-name:container/container2/augment-module:aug-cont/aug-list[aug-list-key='value']
    

Functions List

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值