Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » namespace support for JET Xpaths yet?
namespace support for JET Xpaths yet? [message #26527] Sun, 15 July 2007 19:30 Go to next message
Tim Stephenson is currently offline Tim StephensonFriend
Messages: 18
Registered: July 2009
Junior Member
Hi,

I have a UML model including this snippet
<packagedElement xmi:type="uml:Association"
xmi:id="_CmyWYB4UEdy1OIzpfsW7CQ" name="c1toc2"
memberEnd="_CmyWYR4UEdy1OIzpfsW7CQ
_CmyWZB4UEdy1OIzpfsW7CQ"/>
which I want to be able to extract with an XPath something like this:
<c:get select="//packagedElement[@xmi:type='uml:Association' and
@xmi:id=$attr/@association]"/>
but JET (0.8.1) responds with
Error: No namespace URI found for prefix "xmi"

Is this something I failed to do or a limitation? I can't find any reference
to how i declare the namespace but
found what looks like similar posts pointing at defect 184692

thanks in advance,
tim
Re: namespace support for JET Xpaths yet? [message #26906 is a reply to message #26527] Tue, 17 July 2007 13:46 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Tim:

Not, namespace declaration is not yet supported. But, in your case, I don't
think it would help. Here's why, and here's what to do.

JET loads UML models (with are EMF based) using EMF, and it then traverses
the loaded EObjects - JET has no idea how the objects were persisted on
disk.

When EMF loads an XMI document (such as your UML model), the xmi:type
attribute becomes the EObject's type/EClass. XPath 1.0 has no formally
defined mechanism determining type, but the JET XPath engine can determine
the type of EObjects. It leverages the engines ability to match EClass
names.

Instead of:

//packagedElement[@xmi:type = 'uml:Association']

Try:

// packagedElement[self::Association]

But, in looking more closely at your example, I'm guessing the $attr is
Property object (problably found by iterating over a Class, and accessing
the 'attributes' collection). In which case, you probably want:

$attr/association

which is the result of evaluating getAssociation() on $attr.

I just answered another thread on XPath and XMI. I'm going to create a FAQ
entry, but here are the basics:

1) forgot about looking an the XMI. Instead, think of the EMF Model you are
accessing.
2) think about who your would navigate from an EMF Resource to find the
object
you'd want. In particular, think of the EMF EReferences and EAttributes you
will be using. Here's some pseudo code...

Resource res = ...;
RootType root = (RootType)res.getContents().get(0); // the 'contents' pseudo
EReference
... root.getSomeFeature() ... // the someFeature EReference
... someEObject.getSomeAttribute() ... // the someAttribute EAttribute

3) Write your XPath expression using the 'feature' names from you EMF model.
The initial '/' in an expression maps to the Resource, and 'contents' is the
only valid child of '/'. If your accessing an EAttribute, prefix the name
with '@'. Here's equivalent XPath

/contents/someFeature/@someAttribute

4) XPath on EMF-based models, you can use EClass names instead of feature
names. Here's equivlanet XPath:

/RootType/someFeature/@someAttribute

5) The XPath Engine sees non-containment EReference features, so you can
access these, too. The expression $attr/association takes advantage of this.

Paul



"Tim Stephenson" <tstephen@tibco.com> wrote in message
news:f7dsk2$qk6$1@build.eclipse.org...
> Hi,
>
> I have a UML model including this snippet
> <packagedElement xmi:type="uml:Association"
> xmi:id="_CmyWYB4UEdy1OIzpfsW7CQ" name="c1toc2"
> memberEnd="_CmyWYR4UEdy1OIzpfsW7CQ
> _CmyWZB4UEdy1OIzpfsW7CQ"/>
> which I want to be able to extract with an XPath something like this:
> <c:get select="//packagedElement[@xmi:type='uml:Association' and
> @xmi:id=$attr/@association]"/>
> but JET (0.8.1) responds with
> Error: No namespace URI found for prefix "xmi"
>
> Is this something I failed to do or a limitation? I can't find any
> reference to how i declare the namespace but
> found what looks like similar posts pointing at defect 184692
>
> thanks in advance,
> tim
>
Previous Topic:XPath ancestor axis + XPath node
Next Topic:warnings in example project
Goto Forum:
  


Current Time: Sat Apr 27 04:21:21 GMT 2024

Powered by FUDForum. Page generated in 0.02818 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top