Example to use XMLStorage for writing and reading XML files containing numbers. More...
Public Member Functions | |
void | testWrite () throws Exception |
Write an example XML file to disk. | |
void | testRead () throws Exception |
Read the example file back again. | |
Static Public Member Functions | |
static void | main (String[] args) |
Main function of Example2. |
Example to use XMLStorage for writing and reading XML files containing numbers.
Definition at line 57 of file Example2.java.
static void de.mfuchs.Example2.main | ( | String[] | args ) | [static] |
Main function of Example2.
args | unused command line arguments |
Definition at line 119 of file Example2.java.
References de.mfuchs.Example2.testRead(), and de.mfuchs.Example2.testWrite().
{ Example2 me = new Example2(); try { me.testWrite(); me.testRead(); } catch(Exception e) { e.printStackTrace(); } }
void de.mfuchs.Example2.testRead | ( | ) | throws Exception |
Read the example file back again.
Exception |
Definition at line 94 of file Example2.java.
References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.get(), and de.mfuchs.xmlstorage.XMLPos.go().
Referenced by de.mfuchs.Example2.main().
{ // Einlesen des XML-Files XMLDoc doc = new XMLDoc("example2.xml"); XMLPos pos = new XMLPos(doc); String filename = ""; // Abfrage eines Attributwerts, beispielsweise von "font-filename" if (pos.go("PARAMS/FONT")) { filename = pos.get("font-filename"); pos.back(); } // Ausgabe des ermittelten Werts System.out.println("font filename: " + filename); assertEquals("Arial.ttf", filename); }
void de.mfuchs.Example2.testWrite | ( | ) | throws Exception |
Write an example XML file to disk.
Exception |
Definition at line 63 of file Example2.java.
References de.mfuchs.xmlstorage.XMLStringRef.assign(), de.mfuchs.xmlstorage.XMLIntRef.assign(), de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.create(), de.mfuchs.xmlstorage.XMLPos.put(), and de.mfuchs.xmlstorage.XMLDoc.writeFile().
Referenced by de.mfuchs.Example2.main().
{ XMLDoc doc = new XMLDoc(); XMLPos pos = new XMLPos(doc); // Zusammenstellen der XML-Struktur im Dokument 'doc' pos.create("PARAMS"); pos.put("text", "Testgruppe"); pos.create("COLOR"); new XMLIntRef(pos, "red").assign(234); new XMLIntRef(pos, "green").assign(22); new XMLIntRef(pos, "blue").assign(33); pos.back(); // </COLOR> pos.create("FONT"); new XMLStringRef(pos, "font-filename").assign("Arial.ttf"); new XMLIntRef(pos, "size").assign(12); pos.back(); // </SIZE> pos.back(); // </FONT> pos.back(); // </PARAMS> // Schreiben der XML-Datei doc.writeFile("example2.xml"); }