1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
import java.sql.SQLException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
public class test {
// public Element setChild (Connection conn, int ID_Child) throws NotFoundException, SQLException{
//
//
// Graphic_positionDao graphic_position_X_dao = new Graphic_positionDao();
// Graphic_positionDao graphic_position_Y_dao = new Graphic_positionDao();
// Graphic_positionDao graphic_position_ID_MASG_dao = new Graphic_positionDao();
// String x = graphic_position_X_dao.getObject(conn, ID_Child).getX_MASG_CSG();
// String y = graphic_position_Y_dao.getObject(conn, ID_Child).getX_MASG_CSG();
// String ID_MASG = graphic_position_ID_MASG_dao.getObject(conn, ID_Child).getID_MASG_CSG();
// Element child = new Element(ID_MASG);
// child.addContent(new Element("X").setText(x));
// child.addContent(new Element("Y").setText(y));
// return child;
// }
public static void main(String[] args) {
//
// <rows>
// <row>
// <firstname>Alice</firstname>
// <lastname>Starbuzz</lastname>
// <address>Sunset Read</address>
// </row>
// </row>
//
// Port_typeDao port_type_dao = new Port_typeDao();
Document document = new Document();
Element root = new Element("graphml");
Element key1 = new Element("key1");
Element key2 = new Element("key2");
Element key3 = new Element("key3");
Element child1 = new Element("graph1");
//
// Creating a child for the root element. Here we can see how to
// set the text of an xml element.
//
key1.setAttribute("key1", "x");
key2.setAttribute("key2", "y");
key3.setAttribute("key3", "name");
// key1.addContent(null);
Element child2 = new Element("Node1");
child2.addContent(new Element("X").setText("40"));
child2.addContent(new Element("Y").setText("50"));
child2.addContent(new Element("Name").setText("MASG"));
Element child3 = new Element("Node2");
//child3.setAttribute("key", "y");
child3.addContent(new Element("X").setText("30"));
child3.addContent(new Element("Y").setText("40"));
child3.addContent(new Element("Name").setText("MASG"));
Element child4 = new Element("edge");
//child4.setAttribute("key", "name");
child4.addContent(new Element("target").setText("n1"));
child4.addContent(new Element("source").setText("n2"));
child4.addContent(new Element("Name").setText("FH"));
//
// Add the child to the root element and add the root element as
// the document content.
//
root.setContent(key1);
root.addContent(key2);
root.addContent(key3);
root.addContent(child1);
child1.addContent(child2);
child1.addContent(child3);
child1.addContent(child4);
document.setContent(root);
try {
FileWriter writer = new FileWriter("Graph2.xml");
XMLOutputter outputter = new XMLOutputter();
//
// Set the XLMOutputter to pretty formatter. This formatter
// use the TextMode.TRIM, which mean it will remove the
// trailing white-spaces of both side (left and right)
//
outputter.setFormat(Format.getPrettyFormat());
//
// Write the document to a file and also display it on the
// screen through System.out.
//
outputter.output(document, writer);
outputter.output(document, System.out);
} catch (IOException e) {
e.printStackTrace();
}
}
} |
Partager