XML extraction problem [message #47616] |
Tue, 15 July 2008 08:15  |
Eclipse User |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Hi,
I have a problem extracting the information I want from my EMF-model. I
have created a meta-Model and from the model (.cim) I want to generate
code in the form of .mof (Managed Object Format). I therefore use XPath in
JET to extract information from the model and print it the way I like. But
I can't seem to get the information I want...hopefully you can help me.
This is my simple CIM-model expressed in XML:
<?xml version="1.0" encoding="UTF-8"?>
<saabgroup:CModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:saabgroup="http://saabgroup.com/cim">
<namespace>
<classes xsi:type="saabgroup:CClass" name="aClass">
<qualifiers xsi:type="saabgroup:CClassConstraint"
name="ClassConstraint">
<value>one</value>
<value>two</value>
</qualifiers>
<qualifiers xsi:type="saabgroup:CAbstract" name="Abstract"
subclass="Restricted"/>
<qualifiers xsi:type="saabgroup:CDescription" name="Description"
value="Desc.">
<translatable/>
</qualifiers>
</classes>
</namespace>
</saabgroup:CModel>
I want to extract the second value='two' from my first qualifier. Of what
I have understood from XPath I tried the following:
<c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text() ">
But no result is returned. I ahve also tried many similar variants but
everyone including text() fails.
I did manage to get the first value from:
<c:get select="/CModel/namespace/classes/qualifiers[1]/@value">
But this implies that 'value' would be an attribute in the XML code, and I
still can't get the second value. In the meta model value is expressed as
a list of strings (For the qualifier of the type Description it is just a
string).
Another thing I'm wondering is from where exactly I get the information
when I make reference to myCimModel.cim? Since I can extract information
not expressed in the XML file it all seems much more complicated than just
reading from an XML file.
Best regards
-Mats
|
|
|
Re: XML extraction problem [message #47707 is a reply to message #47616] |
Wed, 16 July 2008 10:59   |
Eclipse User |
|
|
|
Mats:
Looking at your model, it appears to have been created via EMF's XMI
serialization. Am I correct?
I'll answer the rest of your e-mail in two ways:
1) Your model is created by EMF:
JET is uses EMF's reflective interfaces on the loaded EObjects to resolve
XPath expressions and not the XML that you see in the file.
With respect to:
<c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text() ">
How is 'value' declared on the EClass CClass? My guess is that it is as an
unbounded String array? If so, /CModel/namespace/classes/qualifiers/@value
will get you the first value of the array. However, you will have trouble
getting the other values. I have bug 208977 (http://bugs.eclipse.org/208977)
open. For a solution, I'm thinking of allowing something like:
/CModel/namespace/classes/qualifiers/@value[2].
Let me know if you are interested.
2) Your model is not EMF based, or you want to deal directly with the XML
inspite of it being EMF-based.
Open plugin.xml, go to the Extensions tab, expand org.eclipse.jet.transform
and select (transform). Set the modelLoader field to 'org.eclipse.jet.xml'.
This will cause the document to be loaded using the XML DOM instead of via
EMF. Then the XPath engine will traverse the DOM itself.
One note on the XMI created by EMF's serialization. The XMI serialization
omits any attributes whose value is equal to the default specified in the
meta-model. This means that your transformation must know what those default
values are.
Paul
"Mats" <mats.bengtar@saabgroup.com> wrote in message
news:c97f32fb795b360fa7be5b1585538df5$1@www.eclipse.org...
> Hi,
>
> I have a problem extracting the information I want from my EMF-model. I
> have created a meta-Model and from the model (.cim) I want to generate
> code in the form of .mof (Managed Object Format). I therefore use XPath in
> JET to extract information from the model and print it the way I like. But
> I can't seem to get the information I want...hopefully you can help me.
>
> This is my simple CIM-model expressed in XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <saabgroup:CModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:saabgroup="http://saabgroup.com/cim">
> <namespace>
> <classes xsi:type="saabgroup:CClass" name="aClass">
> <qualifiers xsi:type="saabgroup:CClassConstraint"
> name="ClassConstraint">
> <value>one</value>
> <value>two</value>
> </qualifiers>
> <qualifiers xsi:type="saabgroup:CAbstract" name="Abstract"
> subclass="Restricted"/>
> <qualifiers xsi:type="saabgroup:CDescription" name="Description"
> value="Desc.">
> <translatable/>
> </qualifiers>
> </classes>
> </namespace>
> </saabgroup:CModel>
>
>
> I want to extract the second value='two' from my first qualifier. Of what
> I have understood from XPath I tried the following:
> <c:get select="/CModel/namespace/classes/qualifiers[1]/value[1]/text() ">
> But no result is returned. I ahve also tried many similar variants but
> everyone including text() fails.
> I did manage to get the first value from:
> <c:get select="/CModel/namespace/classes/qualifiers[1]/@value">
> But this implies that 'value' would be an attribute in the XML code, and I
> still can't get the second value. In the meta model value is expressed as
> a list of strings (For the qualifier of the type Description it is just a
> string).
>
> Another thing I'm wondering is from where exactly I get the information
> when I make reference to myCimModel.cim? Since I can extract information
> not expressed in the XML file it all seems much more complicated than just
> reading from an XML file.
>
> Best regards
> -Mats
>
|
|
|
|
Re: XML extraction problem [message #47938 is a reply to message #47788] |
Thu, 17 July 2008 09:31   |
Eclipse User |
|
|
|
Mats:
I am considering a 'fix'. My mental block has been the XPath spec, which
doesn't talk about attribute arrays because they do not exist in XML. But,
more generally, the XPath spec allows a numeric predicate expression after
any step, including an attribute step, so, I think I can interpret
$cClass/@value
would refer to the entire collection of objects in the array.
and @cClass/@value[n] would index the array (1-based, because XPath uses
one-based indices).
In theory, this is a simple change. In practice, I am worried that there may
be deep rooted assumptions that attributes are single valued.
Expect a fix in JET 0.9.1 (Ganymede SR1 at the end of September). If you add
yourself as a CC to the defect, you'll get notifications as to when the fix
gets committed and which integration build it is in.
Here's a link to the bug: http://bugs.eclipse.org/208977
Paul
|
|
|
|
|
|
|
|
|
Re: XML extraction problem [message #48184 is a reply to message #48145] |
Fri, 25 July 2008 04:34  |
Eclipse User |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Thanks for all your help!
Unfortunately I am leaving this issue. One of my colleagues will
investigate your recommendations further at some point after the summer.
-Mats
|
|
|
Powered by
FUDForum. Page generated in 0.04947 seconds