Jdom with XMI Files

View: New views
5 Messages — Rating Filter:   Alert me  

Jdom with XMI Files

by Fábio-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hy everybody...
I'm trying to manipulate a XMI file with Jdom, and I have experienced some difficulties doing it.

For example:
All the subnodes of the root Element have the "same name", but have different attributes.
How can I choose a specific "Element", by specifying it's attributes?

Another point is that the attributes started with "xmi:" aren't recognized by Jdom. I've already tested a bunch of things to make it recognizable, but all of them were unsuccessful. =/

I think that my problems are quite easy to solve, but I haven't found anything that could help me in the web. 
If Jdom isn't a great tool with XMI, could you suggest me other?


*Xmi file that i want to read: http://www.omg.org/spec/UML/20061001/Superstructure.cmof


Cheers,
Fábio Leal


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

RE: Jdom with XMI Files

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's a good idea to show the code you were using, then people can tell you where you went wrong.
 
It looks a bit as if you haven't grasped how namespaces work, but without seeing your attempts, that's a guess.
 
Michael Kay


From: jdom-interest-bounces@... [mailto:jdom-interest-bounces@...] On Behalf Of Fabio Leal
Sent: 23 November 2008 03:10
To: jdom-interest@...
Subject: [jdom-interest] Jdom with XMI Files

Hy everybody...
I'm trying to manipulate a XMI file with Jdom, and I have experienced some difficulties doing it.

For example:
All the subnodes of the root Element have the "same name", but have different attributes.
How can I choose a specific "Element", by specifying it's attributes?

Another point is that the attributes started with "xmi:" aren't recognized by Jdom. I've already tested a bunch of things to make it recognizable, but all of them were unsuccessful. =/

I think that my problems are quite easy to solve, but I haven't found anything that could help me in the web. 
If Jdom isn't a great tool with XMI, could you suggest me other?


*Xmi file that i want to read: http://www.omg.org/spec/UML/20061001/Superstructure.cmof


Cheers,
Fábio Leal


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Parent Message unknown RE: Jdom with XMI Files

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
> You were right. I am quite confuse when manipulating namespaces.
> Could you give me a help there?

Please don't go off-list. When people search the archives, they want to find
the answers, not only the questions!
>
> For example, how could I get to the Element:
>
>  <ownedMember xmi:type="cmof:Package" xmi:id="StateMachines"
> name="StateMachines">
>
> (this is a root's child) without using
> rootElement.getchildren() and iterating over it?

Use Element.getChild(name, namespace)
>
> How could I get its child attributes without using
> myElement.getAttributes() and iterating over it?

Use Element.getAttribute(name, namespace)

Michael Kay
http://www.saxonica.com/

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Re: Jdom with XMI Files

by polx :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Le 23-nov.-08 à 04:09, Fabio Leal a écrit :
I'm trying to manipulate a XMI file with Jdom, and I have experienced some difficulties doing it.
For example:
All the subnodes of the root Element have the "same name", but have different attributes.
How can I choose a specific "Element", by specifying it's attributes?

XPath only can do that, it's equivalent to serial search. Something such as:
xmiNS = Namespace.getNamespace("xmi","http://schema.omg.org/spec/XMI/2.1");
XPath x = new XPath("./*[@xmi:type='cmof:Comment'])
x.addNamsepace(xmiNS)

Another point is that the attributes started with "xmi:" aren't recognized by Jdom.

of course they are, they are attributes with namespace.
element.getAttribute("id",xmiNS);

I've already tested a bunch of things to make it recognizable, but all of them were unsuccessful. =/
I think that my problems are quite easy to solve, but I haven't found anything that could help me in the web. 
If Jdom isn't a great tool with XMI, could you suggest me other?

paul


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

smime.p7s (2K) Download Attachment

Re: Jdom with XMI Files

by Fábio-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for everybody, especially Paul Libbrecht and Will Martinez.
I'm going to mix XPath and JDom in my job. XPath is quite easy to
learn and helped me a lot here.
If somebody needs a help with XPath, mail-me and I can show the
tutorial that I used. :D

Cheers,
Fábio Leal

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...