Saturday, March 29, 2014

XMI parsing
































































Hi at all,I am a new member but so long this forum has been a point of reference from which estrarrre important information!I need your help, and in particular I saw an old thread where we talked about parsing xmi:































































How To Parsing XMI?































































I must print the attribute name and the name of the classes.I have just print the attribute's name but i don't found any method that can help me to print the name's classes.































































This is the code that was created by Rauff and edited by me:
































































































Java Code:






































































package mood.xmi;

import java.io.File;

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 = "FP_CFP_tool_v2.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());
//print classes
NodeList listClass = doc.getElementsByTagName(CLASSES);

int totalClass = listClass.getLength();
System.out.println("Total Class : " + totalClass);

for (int i = 0; i < listClass.getLength(); i++) {

Element link = (Element) listClass.item(i);

System.out.println("class name = "+ link.getNodeName());// which metodo can i use to print the names classes?

}
// print attributes

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 = " + " "+ link.getAttribute("name"));

}

} 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();
}
}
}




































































Thank u at all!






























































































No comments:

Post a Comment