You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.
Another feature that I would like to see as a builtin feature in GSL is XML node referencing. I have started to create much more complex model structures and one should avoid redundancy in MOP methods though, there are still situations when it occurs. Let's provide an example to illustrate the basic idea:
In such case, a naive optimization one can approach to avoid the redundant component node is to identify the node component once, let's say using an id attribute and each time we create a component node with the same structure just references to the identified one thanks to a ref attribute. Let's provide an example of the meaning:
In this example, I removed the duplicated component node as well as the name attribute and created two other nodes with the respective names and referencing both to the component identified as mycomponent. The attribute name of the new nodes are only defined at their own level.
More interestingly, I'd like to reference to single nodes that were created in another level or context in my XML model as illustrated in the following example:
In the previous example, I illustrated how to refine the granularity of component nodes using several encapsulated component nodes or just organize them in a way if there are many nodes, they can be identified easily. To solve such a problem and as you may notice, the ref attributes can handle paths in almost a similar way than XPath mechanism's doing. In the example, I am using common.mycomponent to reference to the component node located in the component with the common id and component with the id mycomponent.
One can argue that GSL scripting can fix such a purpose but that's not the point, the point is that I dont want to resort to GSL each time I want to avoid redundancy issue within my XML models. That's why I introduced a few new functions:
In such case, I am still referencing to the same componentmycomponent but this time it's done from a division node. To accomplish that, here is the script code:
Caution: you cannot reference to a node that was not previously defined yet, this could be an enhancement to do that way one doesn't need to focus on the node placement anymore.
The ref attribute can handle a relative path or an absolute path. The both previous examples illustrated these kind of path. The function will first try to find a relative pathid and if it doesn't it looks for an absolute path.
In the relative case, one can use : in order to go up to the parent node, for instance:
Another feature that I would like to see as a builtin feature in GSL is XML node referencing. I have started to create much more complex model structures and one should avoid redundancy in MOP methods though, there are still situations when it occurs. Let's provide an example to illustrate the basic idea:
In such case, a naive optimization one can approach to avoid the redundant
component
node is to identify the nodecomponent
once, let's say using anid
attribute and each time we create acomponent
node with the same structure just references to the identified one thanks to aref
attribute. Let's provide an example of the meaning:In this example, I removed the duplicated
component
node as well as thename
attribute and created two other nodes with the respective names and referencing both to the component identified asmycomponent
. The attributename
of the new nodes are only defined at their own level.More interestingly, I'd like to reference to single nodes that were created in another level or context in my XML model as illustrated in the following example:
In the previous example, I illustrated how to refine the granularity of
component
nodes using several encapsulatedcomponent
nodes or just organize them in a way if there are many nodes, they can be identified easily. To solve such a problem and as you may notice, theref
attributes can handle paths in almost a similar way thanXPath
mechanism's doing. In the example, I am usingcommon.mycomponent
to reference to thecomponent
node located in thecomponent
with thecommon
id andcomponent
with the idmycomponent
.One can argue that GSL scripting can fix such a purpose but that's not the point, the point is that I dont want to resort to GSL each time I want to avoid redundancy issue within my XML models. That's why I introduced a few new functions:
get_node( PATH, NODENAME, INIT )
get_node_attempt( PATH, NODENAME, CONTEXT )
get_node_name( NODE, NODENAME )
get_node_id( NODE, DELIM, NODENAME )
get_node_attribute( NODE, ATTRIBUTE, DELIM, NODENAME )
get_node_length( NODE, NODENAME )
print_node( NODE, NODENAME )
override_attribute( N1, NN, ATTRIBUTE )
append_attribute( N1, NN, ATTRIBUTE )
override_reference( N1, ORIGIN, NODENAME, CONTEXT )
replace_by_reference( N1, N2, NODE_SRC, NODE_DST, CONTEXT )
process_references( NODE_SRC [, NODE_DST [, CONTEXT] ] )
But the most important one is:
process_references( NODE_SRC [, NODE_DST [, CONTEXT] ] )
process_references
will recursively walk across every nodes that matches to a reference (attributeref
) and a specified node name.Using the previous XML example, here is a script that actually processes every
component
that references to othercomponent
nodes:That was an easy model but what about handling this one:
In such case, I am still referencing to the same
component
mycomponent
but this time it's done from adivision
node. To accomplish that, here is the script code:Caution: you cannot reference to a node that was not previously defined yet, this could be an enhancement to do that way one doesn't need to focus on the node placement anymore.
The
ref
attribute can handle a relative path or an absolute path. The both previous examples illustrated these kind of path. The function will first try to find a relative pathid
and if it doesn't it looks for an absolute path.In the relative case, one can use
:
in order to go up to the parent node, for instance:Nota: It is also possible to use
name
attribute instead ofid
to reference to a node.And here is the effective source code:
The text was updated successfully, but these errors were encountered: