Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » XML and JDOM
XML and JDOM [message #880284] Fri, 01 June 2012 19:03 Go to next message
Hela Hakim is currently offline Hela HakimFriend
Messages: 20
Registered: May 2012
Junior Member
Hello all,
this is a XML file (generated by papyrus (. uml)).

*****file XML*******
see joint
********************
I am willing to go before I draw the handle.
This is a JAVA code for the following parcour and display an attribute "xmi: version" of the root. but the display is null, why?

*****code de la classe JDOM2*********
import java.io.*;
import org.jdom2.*;
import org.jdom2.input.*;
import java.util.List;
import java.util.Iterator;
public class JDOM2
{
static org.jdom2.Document document;
static Element racine;
public static void main(String[] args)
{
//On crée une instance de SAXBuilder
SAXBuilder sxb = new SAXBuilder();
try
{
//On crée un nouveau document JDOM avec en argument le fichier XML 
document = sxb.build(new File("C:\\Users\\Hela\\Desktop\\HelaEclipseJDK\\Etudedecas\\etude.uml"));
}
catch(Exception e){}
//On initialise un nouvel élément racine avec l'élément racine du document.
racine = document.getRootElement();
System.out.println(racine.getAttributeValue("xmi:version"));

}}

thanks for your help Smile
Re: XML and JDOM [message #880474 is a reply to message #880284] Sat, 02 June 2012 04:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hela,<br>
<br>
This isn't a UML question,it's a jdom question.&nbsp;&nbsp; It's hard to
imagine what useful thing you're trying to accomplish by processing
directly UML2's XML/XMI serialization rather than working with UML2
instances directly.&nbsp; Have you noted the distinction between these
two methods?<br>
<br>
<table summary="" border="1" cellpadding="3" cellspacing="0"
width="100%">
<tbody>
<tr class="TableRowColor" bgcolor="white">
<td align="right" valign="top" width="1%"><font size="-1">
<code>&nbsp;java.lang.String</code></font></td>
<td><code><b><a
href="http://www.jdom.org/docs/apidocs/org/jdom2/Element.html#getAttributeValue%28java.lang.String%29">getAttributeValue</a></b>(java.lang.String&nbsp;attname)</code>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This returns the attribute value for the
attribute with the given name and within no namespace, null
if there is no such attribute, and the empty string if the
attribute value is empty.</td>
</tr>
<tr class="TableRowColor" bgcolor="white">
<td align="right" valign="top" width="1%"><font size="-1">
<code>&nbsp;java.lang.String</code></font></td>
<td><code><b><a
href="http://www.jdom.org/docs/apidocs/org/jdom2/Element.html#getAttributeValue%28java.lang.String,%20org.jdom2.Namespace%29">getAttributeValue</a></b>(java.lang.String&nbsp;attname,

<a
href="http://www.jdom.org/docs/apidocs/org/jdom2/Namespace.html"
title="class in org.jdom2">Namespace</a>&nbsp;ns)</code>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This returns the attribute value for the
attribute with the given name and within the given
Namespace, null if there is no such attribute, and the empty
string if the attribute value is empty.</td>
</tr>
</tbody>
</table>
<br>
<br>
On 01/06/2012 9:03 PM, Hela Hakim wrote:
<blockquote cite="mid:jqb3lq$7bq$1@xxxxxxxxe.org" type="cite">
<pre wrap="">Hello all,
this is a XML file (generated by papyrus (. uml)).

*****file XML*******
see joint
********************
I am willing to go before I draw the handle.
This is a JAVA code for the following parcour and display an attribute "xmi: version" of the root. but the display is null, why?

*****code de la classe JDOM2*********
import java.io.*;
import org.jdom2.*;
import org.jdom2.input.*;
import java.util.List;
import java.util.Iterator;
public class JDOM2
{
static org.jdom2.Document document;
static Element racine;
public static void main(String[] args)
{
//On cr&Atilde;&copy;e une instance de SAXBuilder
SAXBuilder sxb = new SAXBuilder();
try
{
//On cr&Atilde;&copy;e un nouveau document JDOM avec en argument le fichier XML
document = sxb.build(new File("C:\\Users\\Hela\\Desktop\\HelaEclipseJDK\\Etudedecas\\etude.uml"));
}
catch(Exception e){}
//On initialise un nouvel &Atilde;&copy;l&Atilde;&copy;ment racine avec l'&Atilde;&copy;l&Atilde;&copy;ment racine du document.
racine = document.getRootElement();
System.out.println(racine.getAttributeValue("xmi:version"));

}}
thanks for your help :)
</pre>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XML and JDOM [message #880535 is a reply to message #880474] Sat, 02 June 2012 08:08 Go to previous messageGo to next message
Hela Hakim is currently offline Hela HakimFriend
Messages: 20
Registered: May 2012
Junior Member
I dont understand you Sad
Re: XML and JDOM [message #880558 is a reply to message #880535] Sat, 02 June 2012 09:28 Go to previous messageGo to next message
Vlad Varnica is currently offline Vlad VarnicaFriend
Messages: 546
Registered: July 2009
Location: Milton Keynes - UK
Senior Member
I think that your demand is very interesting and why not to use JDOM ? This is a great xml/java tool and it could read UML2 models as well at xml level if you use Omondo EclipseUML. You can not do it with other open source tools because there are many transformations stages between MOF and the UML diagram which makes it impossible.

Many advantages to this approach. The first is that what is changed with JDOM is live synchronized in the UML diagram. Yes, it is possible to change your model with JDOM and see live synchronization in your diagram. Whaooo !!
Why live synchronization should only be apply at code level between the code and the model ? Metamodel / Model live serialization is also as important as code live synchronization.

Please note that if you want to add your own JDOM code and create complex applications you will be able to do it directly from an UML diagram deployed by Omondo.
You can also create live stereotypes and get java annotations for ORM persistence.

Good initiative - Keep Going -
Bonne chance Hela pour votre projet Smile

[Updated on: Sat, 02 June 2012 09:39]

Report message to a moderator

Re: XML and JDOM [message #880587 is a reply to message #880535] Sat, 02 June 2012 11:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Hela,

Read the Javadoc. Note in particular that the method you're calling is
looking for an attribute in no namespace, but the attribute you're
looking for is in the xmi prefix's namespace. And as I said before,
this forum is not the place to be asking about how to use JDOM.

On 02/06/2012 10:08 AM, Hela Hakim wrote:
> I dont understand you :(


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:UML2 4.0 Migration Guide
Next Topic:qualified association
Goto Forum:
  


Current Time: Thu Mar 28 18:50:43 GMT 2024

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

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

Back to the top