Example for writing and reading a XML file. More...
Public Member Functions | |
void | testWrite () throws Exception |
Write exampe XML file. | |
void | testRead () throws Exception |
Read the example file back again. | |
Static Public Member Functions | |
static void | main (String[] args) |
Main function of Example1. |
Example for writing and reading a XML file.
Definition at line 53 of file Example1.java.
static void de.mfuchs.Example1.main | ( | String[] | args ) | [static] |
Main function of Example1.
args | unused command line arguments |
Definition at line 142 of file Example1.java.
References de.mfuchs.Example1.testRead(), and de.mfuchs.Example1.testWrite().
{ Example1 me = new Example1(); try { me.testWrite(); me.testRead(); } catch(Exception e) { e.printStackTrace(); } }
void de.mfuchs.Example1.testRead | ( | ) | throws Exception |
Read the example file back again.
Exception |
Definition at line 104 of file Example1.java.
References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.getContent(), de.mfuchs.xmlstorage.XMLPos.go(), de.mfuchs.xmlstorage.XMLPos.goDown(), and de.mfuchs.xmlstorage.XMLDoc.readFile().
Referenced by de.mfuchs.Example1.main().
{ XMLDoc doc = new XMLDoc(); // Einlesen des XML-Files doc.readFile("example1.xml"); String txt = ""; String filename = ""; XMLPos pos = new XMLPos(doc); if (pos.goDown("PARAMS")) { if (pos.goDown("TEXT")) { txt = pos.getContent(); pos.back(); } pos.back(); } // Abfrage eines Elementinhalts, beispielsweise von FONT_FILENAME if (pos.go("PARAMS/FONT/FONT_FILENAME")) { filename = pos.getContent(); pos.back(); } // Ausgabe der ermittelten Werte System.out.println("TEXT: " + txt); System.out.println("font filename: " + filename); assertEquals("Arial.ttf", filename); }
void de.mfuchs.Example1.testWrite | ( | ) | throws Exception |
Write exampe XML file.
Exception |
Definition at line 59 of file Example1.java.
References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.create(), de.mfuchs.xmlstorage.XMLPos.setContent(), and de.mfuchs.xmlstorage.XMLDoc.writeFile().
Referenced by de.mfuchs.Example1.main().
{ XMLDoc doc = new XMLDoc(); XMLPos pos = new XMLPos(doc); // Zusammenstellen der XML-Struktur im Dokument 'doc' pos.create("PARAMS"); pos.create("TEXT"); pos.setContent("Testgruppe\nZeile 2", true); pos.back(); // </TEXT> pos.create("COLOR"); pos.create("RED"); pos.setContent("234"); pos.back(); // </RED> pos.create("GREEN"); pos.setContent("22"); pos.back(); // </GREEN> pos.create("BLUE"); pos.setContent("33"); pos.back(); // </BLUE> pos.back(); // </COLOR> pos.create("FONT"); pos.create("FONT_FILENAME"); pos.setContent("Arial.ttf"); pos.back(); // </FONT_FILENAME> pos.create("SIZE"); pos.setContent("12"); pos.back(); // </SIZE> pos.back(); // </FONT> pos.back(); // </PARAMS> // Schreiben der XML-Datei doc.writeFile("example1.xml"); }