Public Member Functions | Static Public Member Functions

de.mfuchs.Example2 Class Reference

Example to use XMLStorage for writing and reading XML files containing numbers. More...

List of all members.

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.

Detailed Description

Example to use XMLStorage for writing and reading XML files containing numbers.

Author:
martin

Definition at line 57 of file Example2.java.


Member Function Documentation

static void de.mfuchs.Example2.main ( String[]  args ) [static]

Main function of Example2.

Parameters:
argsunused 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();
        }
    }

Here is the call graph for this function:

void de.mfuchs.Example2.testRead (  ) throws Exception

Read the example file back again.

Exceptions:
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); 
    }

Here is the call graph for this function:

void de.mfuchs.Example2.testWrite (  ) throws Exception

Write an example XML file to disk.

Exceptions:
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");
    }

Here is the call graph for this function:


The documentation for this class was generated from the following file: