Home » Modeling » M2T (model-to-text transformation) » JET, custom XPAth function and iterating through the nodes which get passed in.
JET, custom XPAth function and iterating through the nodes which get passed in. [message #54800] |
Wed, 07 January 2009 10:02 |
Eclipse User |
|
|
|
Originally posted by: johannes.nel.gmail.com
HI All
First of, I am generating from an xml doc without a schema at this stage.
I have a custom xpath function which gets a nodeset. I iterate through
the nodeset
//CODE///
NodeSet o = (NodeSet)args.get(0);
//Element controlElement = (Element));
Iterator it = o.iterator();
String s = "";
while(it.hasNext())
{
EObject e = (EObject)it.next();
//CODE END///
I get back a an EObject, but would like to be able to access the nodes
attributes (where each item I am iterating over is a node with a
collection of attributes). All casts I have tried thus far have failed ,
this should be something really silly easy but I am failing at this
currently.
In short, how do I cast the EObject to something from which I can access
the attributes specified in the xml.
Thanks
Johan
|
|
|
Re: JET, custom XPAth function and iterating through the nodes which get passed in. [message #54855 is a reply to message #54800] |
Thu, 08 January 2009 06:56 |
Eclipse User |
|
|
|
Originally posted by: johannes.nel.gmail.com
I hacked this with some brutally ugly string parsing, but its crappy and
prone to break (understatement). I would love some pointers on this,
pretty please.
Johannes Nel wrote:
> HI All
>
> First of, I am generating from an xml doc without a schema at this stage.
> I have a custom xpath function which gets a nodeset. I iterate through
> the nodeset
> //CODE///
> NodeSet o = (NodeSet)args.get(0);
>
> //Element controlElement = (Element));
> Iterator it = o.iterator();
> String s = "";
> while(it.hasNext())
> {
> EObject e = (EObject)it.next();
> //CODE END///
> I get back a an EObject, but would like to be able to access the nodes
> attributes (where each item I am iterating over is a node with a
> collection of attributes). All casts I have tried thus far have failed ,
> this should be something really silly easy but I am failing at this
> currently.
>
> In short, how do I cast the EObject to something from which I can access
> the attributes specified in the xml.
>
> Thanks
> Johan
|
|
|
Re: JET, custom XPAth function and iterating through the nodes which get passed in. [message #54883 is a reply to message #54855] |
Thu, 08 January 2009 11:43 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------020205070407000900030105
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Johan,
This article will likely help:
< http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>
http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
I suppose these EObjects instances of AnyType? You can cast to that
interface then, and process with the feature map for the attributes...
In general, given an EObject x that's not a subclass of anything more
concrete, you can use x.eClass().getEAllStructuralFeatures() and for
each one, call x.eGet(feature). Of course each feature will have a
name, and you can use ExtendedMetaData.INSTANCE to access underlying XML
details, like the namespace of the feature...
Johannes Nel wrote:
> I hacked this with some brutally ugly string parsing, but its crappy
> and prone to break (understatement). I would love some pointers on
> this, pretty please.
>
> Johannes Nel wrote:
>> HI All
>>
>> First of, I am generating from an xml doc without a schema at this
>> stage.
>> I have a custom xpath function which gets a nodeset. I iterate
>> through the nodeset
>> //CODE///
>> NodeSet o = (NodeSet)args.get(0);
>> //Element controlElement = (Element));
>> Iterator it = o.iterator();
>> String s = "";
>> while(it.hasNext())
>> {
>> EObject e = (EObject)it.next();
>> //CODE END///
>> I get back a an EObject, but would like to be able to access the
>> nodes attributes (where each item I am iterating over is a node with
>> a collection of attributes). All casts I have tried thus far have
>> failed , this should be something really silly easy but I am failing
>> at this currently.
>>
>> In short, how do I cast the EObject to something from which I can
>> access the attributes specified in the xml.
>>
>> Thanks
>> Johan
--------------020205070407000900030105
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Johan,<br>
<br>
This article will likely help:<a
href=" http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava"><br>
</a>
<blockquote><a
href=" http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava"> http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava</a><br>
</blockquote>
I suppose these EObjects instances of AnyType? You can cast to that
interface then, and process with the feature map for the attributes...<br>
<br>
In general, given an EObject x that's not a subclass of anything more
concrete, you can use x.eClass().getEAllStructuralFeatures() and for
each one, call x.eGet(feature). Of course each feature will have a
name, and you can use ExtendedMetaData.INSTANCE to access underlying
XML details, like the namespace of the feature...<br>
<br>
<br>
Johannes Nel wrote:
<blockquote cite="mid:gk483n$otq$1@build.eclipse.org" type="cite">I
hacked this with some brutally ugly string parsing, but its crappy and
prone to break (understatement). I would love some pointers on this,
pretty please.
<br>
<br>
Johannes Nel wrote:
<br>
<blockquote type="cite">HI All
<br>
<br>
First of, I am generating from an xml doc without a schema at this
stage.
<br>
I have a custom xpath function which gets a nodeset. I iterate through
the nodeset
<br>
//CODE///
<br>
NodeSet o = (NodeSet)args.get(0);
<br>
//Element controlElement = (Element));
<br>
Iterator it = o.iterator();
<br>
String s = "";
<br>
while(it.hasNext())
<br>
{
<br>
EObject e = (EObject)it.next();
<br>
//CODE END///
<br>
I get back a an EObject, but would like to be able to access the nodes
attributes (where each item I am iterating over is a node with a
collection of attributes). All casts I have tried thus far have failed
, this should be something really silly easy but I am failing at this
currently.
<br>
<br>
In short, how do I cast the EObject to something from which I can
access the attributes specified in the xml.
<br>
<br>
Thanks
<br>
Johan
<br>
</blockquote>
</blockquote>
</body>
</html>
--------------020205070407000900030105--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: JET, custom XPAth function and iterating through the nodes which get passed in. [message #54909 is a reply to message #54883] |
Thu, 08 January 2009 16:27 |
Eclipse User |
|
|
|
Originally posted by: johannes.nel.gmail.com
my naviety with java shows now, but I cannot seem to find the Anytype,
what package do i need to include?
I currently have emf, emf.codegen emf.codegen.ecore and jet (other what
I would see in a normal plugin project)
Ed Merks wrote:
> Johan,
>
> This article will likely help:
> < http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>
>
> http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
>
> I suppose these EObjects instances of AnyType? You can cast to that
> interface then, and process with the feature map for the attributes...
>
> In general, given an EObject x that's not a subclass of anything more
> concrete, you can use x.eClass().getEAllStructuralFeatures() and for
> each one, call x.eGet(feature). Of course each feature will have a
> name, and you can use ExtendedMetaData.INSTANCE to access underlying XML
> details, like the namespace of the feature...
>
>
> Johannes Nel wrote:
>> I hacked this with some brutally ugly string parsing, but its crappy
>> and prone to break (understatement). I would love some pointers on
>> this, pretty please.
>>
>> Johannes Nel wrote:
>>> HI All
>>>
>>> First of, I am generating from an xml doc without a schema at this
>>> stage.
>>> I have a custom xpath function which gets a nodeset. I iterate
>>> through the nodeset
>>> //CODE///
>>> NodeSet o = (NodeSet)args.get(0);
>>> //Element controlElement = (Element));
>>> Iterator it = o.iterator();
>>> String s = "";
>>> while(it.hasNext())
>>> {
>>> EObject e = (EObject)it.next();
>>> //CODE END///
>>> I get back a an EObject, but would like to be able to access the
>>> nodes attributes (where each item I am iterating over is a node with
>>> a collection of attributes). All casts I have tried thus far have
>>> failed , this should be something really silly easy but I am failing
>>> at this currently.
>>>
>>> In short, how do I cast the EObject to something from which I can
>>> access the attributes specified in the xml.
>>>
>>> Thanks
>>> Johan
|
|
|
Re: JET, custom XPAth function and iterating through the nodes which get passed in. [message #55150 is a reply to message #54883] |
Mon, 12 January 2009 14:43 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_001A_01C9749A.36DB5820
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Johannes (& Ed):
It is almost certainly an AnyType object. But before you go down that =
road, let me make a couple of alternative suggestions:
Alternative 1 (This requires JET 0.9.0 or later)
-----------------
Change JET's model loader to XML DOM. That way, what you'll receive in =
your function is org.w3c.dom.Node and sub-types. To do this,
Open your JET transforms plugin.xml, go the the Extensions tab. Expand =
and select the '(transform') element, and enter 'org.eclipse.jet.xml' =
(without the quotes) in the modelLoader field.
Alternative 2
------------------
Use the JET XPath engine to navigate the node-set. The best example of =
doing this is the sort() function that was introduced in JET 0.9. Here's =
a link to the source:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/=
plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/f unctions/extr=
as/SortFunction.java?revision=3D1.1&root=3DModeling_Proj ect&view=3Dmarkup=
Alternative 3
------------------
Explain what you'd like to do in your function. Maybe we can figure out =
a way to do this via something less complex. Or maybe, this is something =
that requires some enhancement to JET.
Paul
------=_NextPart_000_001A_01C9749A.36DB5820
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.2900.3492" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Johannes (& Ed):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>It is almost certainly an AnyType =
object. But=20
before you go down that road, let me make a couple of alternative=20
suggestions:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Alternative 1 (This requires JET 0.9.0 =
or=20
later)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-----------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Change JET's model loader to XML DOM. =
That way,=20
what you'll receive in your function is org.w3c.dom.Node and sub-types. =
To do=20
this,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Open your JET transforms plugin.xml, go =
the the=20
Extensions tab. Expand and select the '(transform') element, and enter=20
'org.eclipse.jet.xml' (without the quotes) in the modelLoader=20
field.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Alternative 2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Use the JET XPath engine to navigate =
the node-set.=20
The best example of doing this is the sort() function that was =
introduced in JET=20
0.9. Here's a link to the source:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .ecli=
pse.jet/plugins/org.eclipse.jet/src/org/eclipse/jet/internal /xpath/functi=
ons/extras/SortFunction.java?revision=3D1.1&root=3DM odeling_Project&a=
mp;view=3Dmarkup">http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2=
t/org.eclipse.jet/plugins/org.eclipse.jet/src/org/eclipse/je t/internal/xp=
ath/functions/extras/SortFunction.java?revision=3D1.1&am p;root=3DModeling=
_Project&view=3Dmarkup</A></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Alternative 3</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Explain what you'd like to do in your =
function.=20
Maybe we can figure out a way to do this via something less complex. Or =
maybe,=20
this is something that requires some enhancement to JET.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Paul</FONT></DIV></BODY></HTML>
------=_NextPart_000_001A_01C9749A.36DB5820--
|
|
| |
Goto Forum:
Current Time: Sat Dec 21 17:20:44 GMT 2024
Powered by FUDForum. Page generated in 0.06077 seconds
|