EMF - XPath Syntax

ciever2k

Mitglied
Ich habe die Frage schon im XML Forum gestellt, allerdings bisher ohne Antwort. Nun hoffe ich, dass es kein EMF spezifisches Syntax Gebastel ist.

Code:
//@defines.1/@defines.0/@defines.0

Was genau besagt die oben genannte Syntax?

Der Aufbau des Model sieht so aus:

Code:
<Metamodel:Webapplication xmlns:xmi="http://www.omg.org/XMI" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:Metamodel="Metamodel" name="Blah">
 <defines name="K_Glucky">
  <defines name="EG Weltenreiter" type="EG" criticality="0" testobject="true">
    <defines name="R Hier" type="R" refersTo="//@defines.1/@defines.0/@defines.0" testobject="false"/>
    <defines name="R Steh" type="R" refersTo="//@defines.2/@defines.0/@defines.0" testobject="false"/>
    <defines name="R Ich" type="R" refersTo="//@defines.3/@defines.0/@defines.0" testobject="false"/>
    <defines name="R Am" type="R" refersTo="//@defines.4/@defines.0/@defines.0" testobject="false"/>
    <defines name="L See" type="L" refersTo="//@defines.6/@defines.0/@defines.0" testobject="false"/>
  </defines>
</defines>
</Metamodel:Webapplication>
 
Zuletzt bearbeitet:
Hi,

ich nehm mal stark an, dass die Nummer hinter dem Punkt die Nummer des jeweiligen Knotens (angefangen bei 0) angibt.

Code:
//@defines.1/@defines.0/@defines.0

ist dann wohl der im der 2te der erste "definies"-Knoten im ersten "defines"-Knoten im zweiten "defines"-Knoten.

Oder etwas anschaulicher als :

Code:
|- defines #0
    |- defines #0
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #1
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #2
        |- defines #0
        |- defines #1
        |- defines #2
|- defines #1
    |- defines #0
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #1
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #2
        |- defines #0
        |- defines #1
        |- defines #2
|- defines #2
    |- defines #0
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #1
        |- defines #0
        |- defines #1
        |- defines #2
    |- defines #2
        |- defines #0
        |- defines #1
        |- defines #2

der unterstrichene ;)
 
Danke aber ganz so ist es nicht, es ist nämlich kein XPath. In der Mailinglist von EMF wurde mir gesagt, dass dies EMF spezifisch ist.

Code:
It's not really xpath...

String org.eclipse.emf.ecore.InternalEObject.eURIFragmentSegment(EStructuralFeature eFeature, EObject eObject)

Returns the fragment segment that, when passed to eObjectForURIFragmentSegment, will resolve to the given object in this object's given feature. 

The feature argument may be null in which case it will be deduced, if possible. The default result will be of the form: 

  "@<feature-name>[.<index>]"

    

The index is used only for many-valued features; it represents the position within the list. 

Parameters: 

eFeature the feature relating the given object to this object, or null. 

eObject the object to be identified. 

Returns: 

the fragment segment that resolves to the given object in this object's given feature. 

The first segment walks from the Resource.getContents() to a direct child and /0 is reduced to just /; from there the above syntax is used to walk down the tree.

Note that you might want to make the name feature of the "defines" feature's type be a eKey with respect to the "defines" containment reference such that you end up with  segments like @defines[name='K_Glucky'].  Of course that assumes that the names within any particular "defines" containment reference will be unique. 

Any ideas?

 

And for your intereset, this is a code part of the model:

<Metamodel:Webapplication xmlns:xmi="http://www.omg.org/XMI"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xmlns:Metamodel="Metamodel" name="Blah">

 <defines name="K_Glucky">

  <defines name="EG Weltenreiter" type="EG" criticality="0" 

testobject="true">

    <defines name="R Hier" type="R" 

refersTo="//@defines.1/@defines.0/@defines.0" testobject="false"/>

    <defines name="R Steh" type="R" 

refersTo="//@defines.2/@defines.0/@defines.0" testobject="false"/>

    <defines name="R Ich" type="R" 

refersTo="//@defines.3/@defines.0/@defines.0" testobject="false"/>

    <defines name="R Am" type="R" 

refersTo="//@defines.4/@defines.0/@defines.0" testobject="false"/>

    <defines name="L See" type="L" 

refersTo="//@defines.6/@defines.0/@defines.0" testobject="false"/>

  </defines>

</defines>

</Metamodel:Webapplication>

Danke trotzdem für Deine Mühe.
 
Zurück