Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 package de.mfuchs;
00040
00041 import static org.junit.Assert.assertEquals;
00042
00043 import org.junit.Test;
00044
00045 import de.mfuchs.xmlstorage.XMLDoc;
00046 import de.mfuchs.xmlstorage.XMLIntRef;
00047 import de.mfuchs.xmlstorage.XMLPos;
00048 import de.mfuchs.xmlstorage.XMLStringRef;
00049
00050
00051
00052
00053
00054
00055
00056
00057 public class Example2
00058 {
00059
00060
00061
00062
00063 @Test public void testWrite() throws Exception
00064 {
00065 XMLDoc doc = new XMLDoc();
00066 XMLPos pos = new XMLPos(doc);
00067
00068
00069 pos.create("PARAMS");
00070 pos.put("text", "Testgruppe");
00071
00072 pos.create("COLOR");
00073 new XMLIntRef(pos, "red").assign(234);
00074 new XMLIntRef(pos, "green").assign(22);
00075 new XMLIntRef(pos, "blue").assign(33);
00076 pos.back();
00077
00078 pos.create("FONT");
00079 new XMLStringRef(pos, "font-filename").assign("Arial.ttf");
00080 new XMLIntRef(pos, "size").assign(12);
00081 pos.back();
00082 pos.back();
00083 pos.back();
00084
00085
00086 doc.writeFile("example2.xml");
00087 }
00088
00089
00090
00091
00092
00093
00094 @Test public void testRead() throws Exception
00095 {
00096
00097 XMLDoc doc = new XMLDoc("example2.xml");
00098
00099 XMLPos pos = new XMLPos(doc);
00100 String filename = "";
00101
00102
00103 if (pos.go("PARAMS/FONT")) {
00104 filename = pos.get("font-filename");
00105 pos.back();
00106 }
00107
00108
00109 System.out.println("font filename: " + filename);
00110
00111 assertEquals("Arial.ttf", filename);
00112 }
00113
00114
00115
00116
00117
00118
00119 public static void main(String[] args)
00120 {
00121 Example2 me = new Example2();
00122
00123 try {
00124 me.testWrite();
00125 me.testRead();
00126 } catch(Exception e) {
00127 e.printStackTrace();
00128 }
00129 }
00130 }