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.XMLPos;
00047
00048
00049
00050
00051
00052
00053 public class Example1
00054 {
00055
00056
00057
00058
00059 @Test public void testWrite() throws Exception
00060 {
00061 XMLDoc doc = new XMLDoc();
00062 XMLPos pos = new XMLPos(doc);
00063
00064
00065 pos.create("PARAMS");
00066 pos.create("TEXT");
00067 pos.setContent("Testgruppe\nZeile 2", true);
00068 pos.back();
00069
00070 pos.create("COLOR");
00071 pos.create("RED");
00072 pos.setContent("234");
00073 pos.back();
00074
00075 pos.create("GREEN");
00076 pos.setContent("22");
00077 pos.back();
00078
00079 pos.create("BLUE");
00080 pos.setContent("33");
00081 pos.back();
00082 pos.back();
00083
00084 pos.create("FONT");
00085 pos.create("FONT_FILENAME");
00086 pos.setContent("Arial.ttf");
00087 pos.back();
00088
00089 pos.create("SIZE");
00090 pos.setContent("12");
00091 pos.back();
00092 pos.back();
00093 pos.back();
00094
00095
00096 doc.writeFile("example1.xml");
00097 }
00098
00099
00100
00101
00102
00103
00104 @Test public void testRead() throws Exception
00105 {
00106 XMLDoc doc = new XMLDoc();
00107
00108
00109 doc.readFile("example1.xml");
00110
00111 String txt = "";
00112 String filename = "";
00113
00114 XMLPos pos = new XMLPos(doc);
00115
00116 if (pos.goDown("PARAMS")) {
00117 if (pos.goDown("TEXT")) {
00118 txt = pos.getContent();
00119 pos.back();
00120 }
00121 pos.back();
00122 }
00123
00124
00125 if (pos.go("PARAMS/FONT/FONT_FILENAME")) {
00126 filename = pos.getContent();
00127 pos.back();
00128 }
00129
00130
00131 System.out.println("TEXT: " + txt);
00132 System.out.println("font filename: " + filename);
00133
00134 assertEquals("Arial.ttf", filename);
00135 }
00136
00137
00138
00139
00140
00141
00142 public static void main(String[] args)
00143 {
00144 Example1 me = new Example1();
00145
00146 try {
00147 me.testWrite();
00148 me.testRead();
00149 } catch(Exception e) {
00150 e.printStackTrace();
00151 }
00152 }
00153 }