Results 1 to 12 of 12
  1. #1
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default How To Parsing XMI?

    Please help me, give me a tutorial how to parsing XMI?
    XMI or xmi :D

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Sorry, I've never even heard of xmi. What type of file is this? Is it related to XML?

    Oh, and welcome to the forum by the way!

  3. #3
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    XMI look like XML, but XMI is as an interchange format for UML models.

    In this case i try to parsing XMI to get value matric of design OOP
    please help me to parsing file XMI :D

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Actually it's about metadata interchange mechanism, right? So how it's related with Java? Do you want to find a parser in Java?

  5. #5
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Actually it's about metadata interchange mechanism, right? So how it's related with Java? Do you want to find a parser in Java?
    Yup.
    How to parsing xmi in java?
    Hehehe :D

  6. #6
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    4

    Default

    Since it is XML, do you already know how to parse XML?

  7. #7
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by curmudgeon View Post
    Since it is XML, do you already know how to parse XML?
    yes i know how to parse XML, but parse xmi i can't :(

  8. #8
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    this is my source code

    Java Code:
    public class XMIReaderu {
    
        public static void main(String args[]){
    // get the default repository
            MDRepository repository = MDRManager.getDefault().getDefaultRepository();
    
            // start a write transaction
            boolean fail = true;
            repository.beginTrans(true);
            try {
                // create a new MOF extent
                RefPackage mof = repository.createExtent("MyMOFExtent");
                // create an XMIReader
                XMIReader reader = XMIReaderFactory.getDefault().createXMIReader();
                // read the document
                reader.read(new File("test.xmi").toURL().toString(), mof);
                // everything succeeded => set fail flag to false
                fail = false;
            } catch (Exception e) {
                System.out.println("Fatal error reading XMI.");
                e.printStackTrace();
            } finally {
                // commit/rollback the transaction
                repository.endTrans(fail);
            }
        }
    }
    And this error
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/openide/util/Lookup
            at org.netbeans.api.mdr.MDRManager.getDefault(MDRManager.java:53)
            at mood.input.XMIReaderu.main(XMIReaderu.java:20)
    Caused by: java.lang.ClassNotFoundException: org.openide.util.Lookup
            at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
            ... 2 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by rauff View Post
    yes i know how to parse XML, but parse xmi i can't :(
    Structure are the same, you may override few of them.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by rauff View Post
    this is my source code

    Java Code:
    public class XMIReaderu {
    
        public static void main(String args[]){
    // get the default repository
            MDRepository repository = MDRManager.getDefault().getDefaultRepository();
    
            // start a write transaction
            boolean fail = true;
            repository.beginTrans(true);
            try {
                // create a new MOF extent
                RefPackage mof = repository.createExtent("MyMOFExtent");
                // create an XMIReader
                XMIReader reader = XMIReaderFactory.getDefault().createXMIReader();
                // read the document
                reader.read(new File("test.xmi").toURL().toString(), mof);
                // everything succeeded => set fail flag to false
                fail = false;
            } catch (Exception e) {
                System.out.println("Fatal error reading XMI.");
                e.printStackTrace();
            } finally {
                // commit/rollback the transaction
                repository.endTrans(fail);
            }
        }
    }
    And this error
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/openide/util/Lookup
            at org.netbeans.api.mdr.MDRManager.getDefault(MDRManager.java:53)
            at mood.input.XMIReaderu.main(XMIReaderu.java:20)
    Caused by: java.lang.ClassNotFoundException: org.openide.util.Lookup
            at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
            ... 2 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    Did you added all external packages which are used in your code? From where you get that, seems to me you've read that page partially.

  11. #11
    rauff is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    Hay guys i already can import file xmi :D

    You can see my file xmi in my blog Parsing XMI Code Program

    Java Code:
    package mood.xmi;
    
    import java.io.File;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    
    import java.lang.String;
    
    public class forum {
    
        final static String ATTRIBUTES = "UML:Attribute";
        final static String METHODS = "UML:Operation";
        final static String CLASSES = "UML:Classifier.feature"; //masih salah
        final static String COUPLINGS = "UML:AssociationEnd";
        final static String CLASS_INHERITANCES = "UML:GeneralizableElement.generalization";
        final static String FILE_ADDRESS = "test.xmi";
    
        public static void main(String args[]) {
            try {
    
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                Document doc = docBuilder.parse(new File(FILE_ADDRESS));
    
                // normalize text representation
                doc.getDocumentElement().normalize();
                System.out.println("==============================");
                System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
    
                NodeList listClass = doc.getElementsByTagName(CLASSES);
                int totalClass = listClass.getLength();
                System.out.println("Total Class : " + totalClass);
    
                NodeList listAttributes = doc.getElementsByTagName(ATTRIBUTES);
                int totalAttributes = listAttributes.getLength();
                System.out.println("Total Attribute : " + totalAttributes);
    
                NodeList linksAtributesHiding = doc.getElementsByTagName(ATTRIBUTES);
                for (int i = 0; i < linksAtributesHiding.getLength(); i++) {
    
                    Element link = (Element) linksAtributesHiding.item(i);
    
                    System.out.println("attribute value = " + link.getAttribute("visibility"));
    
                }
    
            } catch (SAXParseException err) {
                System.out.println("** Parsing error" + ", line "
                        + err.getLineNumber() + ", uri " + err.getSystemId());
                System.out.println(" " + err.getMessage());
    
            } catch (SAXException e) {
                Exception x = e.getException();
                ((x == null) ? e : x).printStackTrace();
    
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }
    And a result like this
    ==============================
    Root element of the doc is XMI
    Total Class : 3
    Total Attribute : 4
    attribute value = public
    attribute value = private
    attribute value = public
    attribute value = public

    But now i have some problems with my program, how to i can get total attributes value is public. I have 4 attributes, and 3 attributes value is public and 1 attribute value is private. How i can get 3 attributes value is public to integer?

    Please help me :D

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. help with parsing
    By ace_03 in forum New To Java
    Replies: 15
    Last Post: 11-24-2009, 09:02 PM
  2. Parsing
    By Matt Sakko in forum New To Java
    Replies: 14
    Last Post: 03-21-2009, 04:49 PM
  3. Xml Parsing
    By Nomad in forum XML
    Replies: 12
    Last Post: 02-22-2009, 11:19 AM
  4. xml parsing help
    By tankhardrive in forum XML
    Replies: 2
    Last Post: 02-11-2009, 11:45 PM
  5. Parsing URL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •