Example to use XMLStorage for writing and reading XML files. 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 Example3. |
Example to use XMLStorage for writing and reading XML files.
Definition at line 58 of file Example3.java.
static void de.mfuchs.Example3.main | ( | String[] | args ) | [static] |
Main function of Example3.
args | unused command line arguments |
Definition at line 117 of file Example3.java.
References de.mfuchs.Example3.testRead(), and de.mfuchs.Example3.testWrite().
{ Example3 me = new Example3(); try { me.testWrite(); me.testRead(); } catch(Exception e) { e.printStackTrace(); } }
void de.mfuchs.Example3.testRead | ( | ) | throws Exception |
Read the example file back again.
Exception |
Definition at line 84 of file Example3.java.
References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.get(), de.mfuchs.xmlstorage.XMLPos.go(), de.mfuchs.xmlstorage.XMLInt.intValue(), and de.mfuchs.xmlstorage.XMLDoc.readFile().
Referenced by de.mfuchs.Example3.main().
{ XMLDoc doc = new XMLDoc(); // Einlesen des XML-Files doc.readFile("example3.xml"); XMLPos pos = new XMLPos(doc); int stopbits = 0; String parity = ""; // Abfrage der Attributwerte des Elements "Y_ACHSE" if (pos.go("Y_ACHSE")) { stopbits = new XMLInt(pos, "Stopbits").intValue(); parity = pos.get("Parity"); pos.back(); } // Ausgabe der ermittelten Werte System.out.println("Stopbits: " + stopbits); System.out.println("Parity: " + parity); assertTrue("Stopbits", 1==stopbits); assertEquals("Parity", "N", parity); }
void de.mfuchs.Example3.testWrite | ( | ) | throws Exception |
Write an example XML file to disk.
Exception |
Definition at line 64 of file Example3.java.
References 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.Example3.main().
{ XMLDoc doc = new XMLDoc(); XMLPos pos = new XMLPos(doc); // Zusammenstellen der XML-Struktur im Dokument 'doc' pos.create("Y_ACHSE"); new XMLIntRef(pos, "Stopbits").assign(1); pos.put("Parity", "N"); pos.back(); // Schreiben der XML-Datei doc.writeFile("example3.xml"); }