XML extraction problem [message #47616] |
Tue, 15 July 2008 12:15 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 14:59 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Paul Elder![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=pelder%40ca.ibm.com) Messages: 849 Registered: July 2009 |
Senior Member |
|
|
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 #47788 is a reply to message #47707] |
Thu, 17 July 2008 07:51 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Thanks Paul.
You are correct, my model is EMF-based. But your second alternative is
also very helpful, since I would find it easier to deal directly with the
XML. But to the problem. Value is declared as a string array (i.e. an
unbounded list of strings). So what is there to do next? Have you found a
solution to get around this issue or is it just to wait for this 'bug' to
get resolved?
Best regards
Mats
|
|
|
Re: XML extraction problem [message #47938 is a reply to message #47788] |
Thu, 17 July 2008 13:31 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Paul Elder![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=pelder%40ca.ibm.com) Messages: 849 Registered: July 2009 |
Senior Member |
|
|
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 #47998 is a reply to message #47707] |
Tue, 22 July 2008 09:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Paul,
It doesn't seem to work to set the modelLoader to 'org.eclipse.jet.xml'.
It still doesn't read the information from just the xml, because I still
get information that isn't there. Are you sure that is the way to set the
input?
Best regards
Mats Bengtar
|
|
|
|
Re: XML extraction problem [message #48057 is a reply to message #48028] |
Wed, 23 July 2008 07:27 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Ok, thanks. I think you misinterpreted my question, or I just didn't
understand your answer. I want to read directly from the xml-file.
Lets say I have a value 'subclass' for each qualifier. The value is
choosen as an enumeration, the options are "ToSubclass" and "Restricted".
The default value is set to ToSubclass.
So if I then write <c:get select="$qualifiers[1]/@subclass"/> I will get
Restricted returned if the value has been changed to this in the model or
I will get nothing returned since default values are not written in the
xml-file. Is this possible to configure?
Best regards
Mats Bengtar
|
|
|
|
Re: XML extraction problem [message #48116 is a reply to message #48087] |
Thu, 24 July 2008 08:33 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: mats.bengtar.saabgroup.com
Paul,
It doesn't work for me. I have set:
modelLoader: org.eclipse.jet.xml
modelExtension: xml
It doesn't read from just from the xml. If I do...
<c:get select="$qualifiers[1]/@subclass"/>
...I get a value returned even if it isn't changed from default. Now, the
problem might be that subclass is an enumeration so it is always set to a
value != null.
I have experienced that it reports an error for e.g. a string, since the
default is set to null. So my conclusion is that it's not taking info just
from the xml, even though it might seem so when working with strings.
Best regards
Mats
|
|
|
|
Re: XML extraction problem [message #48184 is a reply to message #48145] |
Fri, 25 July 2008 08:34 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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.04893 seconds