Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello every one help please :
Here is my java code that makes parcour an xml file to retrieve data and build with these data with a graph api jgraph
I will represent the graph in a Jframe
the result I get only empty JFrame
it seems it does not run the first instructions
Java
	import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;

	import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

	import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.swing.mxGraphComponent;
	public class Tester extends JFrame {
		 
		  /** Pour éviter un warning venant du JFrame */
		  private static final long serialVersionUID = -8123406571694511514L;
		 
		  public static void main(String[] args) {
		
		 
		    
		  System.out.println("Bonjour");
 
		 try {
		    	
             File nomf = new File("C:/Users/Hela/Desktop/1_auto.xml");
		    	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		    	DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		    	Document doc = dBuilder.parse(nomf);
		    	doc.getDocumentElement().normalize();
		    	System.out.println("Bonjour");
		    	
		    	mxGraph graph = new mxGraph();
			    Object parent = graph.getDefaultParent();
			 
			  graph.getModel().beginUpdate();

		    	//System.out.println("root of xml file" + doc.getDocumentElement().getNodeName());
		    	NodeList nodes = doc.getElementsByTagName("triplet");
		    	System.out.println("==========================");
		    	
		        Object racine= graph.insertVertex(parent, null,"brad pit", 20, 20, 80, 30);
		        
  		    	for (int i = 0; i < nodes.getLength(); i++) {
		    	Node node = nodes.item(i);

		    	if (node.getNodeType() == Node.ELEMENT_NODE) {
		    	Element element = (Element) node;
		    
		    	Object obj1 =graph.insertVertex(parent, null,getValue("object", element) , 20, 20, 80, 30,
		    	mxConstants.STYLE_SHAPE + "="+mxConstants.SHAPE_ELLIPSE);
		    	 graph.insertEdge(parent, null,getValue("predicate", element) , racine, obj1);
		    	
		    
		    	}
		    	
		    	}}
		 
		    	
		    	
		    		catch (Exception ex) {
				ex.printStackTrace();}
		    	
		    	
		    	
		    	
		    	
		    finally {
		      graph.getModel().endUpdate();
		    }
		 
		    mxGraphComponent graphComponent = new mxGraphComponent(graph);
		    getContentPane().add(graphComponent);
		    	}
	
		    	
		    	
		    	
		    	private static String getValue(String tag, Element element) {
		    		NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
		    		Node node = (Node) nodes.item(0);
		    		return node.getNodeValue();
		    		}
		    	
		
		  
			 JPanel contentPane;
			    Graphe frame = new Graphe();
			    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			    frame.setSize(400, 320s);
			    frame.setVisible(true);
			    
			    
				frame.setBounds(100, 100, 450, 300);
			contentPane = new JPanel();
				contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
				contentPane.setLayout(new BorderLayout(0, 0));
				
			    
			    
			    System.out.println("Bonjour");
		  }
		  
		  
		
		    	}	
Posted
Comments
karthik Udhayakumar 3-May-14 15:13pm    
first instrcutions----? what is it?pls elaborate
aureol 3-May-14 15:23pm    
read the file
parse xml file
browse the xml file
create the graph ....
wikus70 5-May-14 2:26am    
Can you post the content of the xml file? I'll play with the code a bit and see if I can help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900