corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

enhance property instance's relative XPATH traversal #29

Closed sekur closed 8 years ago

sekur commented 8 years ago

From the context of an Event handler routine, it should be easier to find relative data element(s) from the perspective of the prop which generated the event. Since the prop which triggers the event of interest can be any sub-tree element inside the Model, we need a way to extract sufficient level of XPath details that we can then extend from in order to get to the data element(s) of interest.

We will need to enhance the Property instance to provide access to the XPath instance which you can tweak in order to allow you to grab the related data of interest.

This enhancement was derived from suggestions from @ramukima.

sekur commented 8 years ago

Here's an example:

xpath = prop.path.trim('/foo/bar').extends('address')

With the newly modified xpath you can use it in various ways:

BTW, new XPath instances are schema-aware so if you try to alter the expression to no longer be part of the underlying schema, it will throw an error.