Public Member Functions | Static Public Member Functions

de.mfuchs.XMLTest Class Reference

Examples used as tests for XMLStorage. More...

List of all members.

Public Member Functions

void test1 () throws Exception
 Test 1 for XMLStorage: navigate in XML data.
void test2Write () throws Exception
 Write an example XML file.
void test2Read () throws Exception
 Read back the example file and print some of its content.
void test3Write () throws Exception
 Test 3 of XMLStorage: write another example file.
void testStreamingReader1 () throws Exception
 Stream test 1 for XMLStreamReader.
void testStreamingWriter () throws Exception
 Stream test for XMLStreamWriter.
void testStreamingReader2 () throws Exception
 Stream test 2 for XMLStreamReader.

Static Public Member Functions

static void main (String[] args)
 Main function of XMLTest.

Detailed Description

Examples used as tests for XMLStorage.

Author:
Martin Fuchs

Definition at line 63 of file XMLTest.java.


Member Function Documentation

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

Main function of XMLTest.

Parameters:
argsunused command line arguments

Definition at line 331 of file XMLTest.java.

References de.mfuchs.XMLTest.test1(), de.mfuchs.XMLTest.test2Read(), de.mfuchs.XMLTest.test2Write(), de.mfuchs.XMLTest.test3Write(), de.mfuchs.XMLTest.testStreamingReader1(), and de.mfuchs.XMLTest.testStreamingReader2().

    {
        XMLTest me = new XMLTest();

        try {
            me.test1();

            me.test2Write();
            me.test2Read();

            me.test3Write();

            me.testStreamingReader1();
            me.testStreamingReader2();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.test1 (  ) throws Exception

Test 1 for XMLStorage: navigate in XML data.

Exceptions:
Exception

Definition at line 69 of file XMLTest.java.

References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.go(), de.mfuchs.xmlstorage.XMLPos.goDown(), de.mfuchs.xmlstorage.XMLIntRef.intValue(), de.mfuchs.xmlstorage.XMLDoc.readFile(), and de.mfuchs.xmlstorage.XMLDoc.writeFile().

Referenced by de.mfuchs.XMLTest.main().

    {
//      String path = "poem.xml";
//      String path = "machines.xml";
        String path = "packets.xml";

        XMLDoc doc = new XMLDoc();

        doc.readFile(path);

        XMLPos pos = new XMLPos(doc);
        pos.goDown("get_packets");

        //pos.putSubattrib("options", "hide-inactive", String.valueOf(false));

        XMLChildrenFilter filter = new XMLChildrenFilter(pos, "packet");

        for(XMLNode node: filter) {
            XMLIntRef dbId = new XMLIntRef(node, "db_id");
            //db_id.assign(-999);
            System.out.println("db_id: " + dbId.intValue());

            int x = node.getInt("db_id", 12345).intValue();
            System.out.println("x: " + x);

            System.out.println(node + " \"" + node.get("name") + "\"");
        }

        pos.back();

        doc.writeFile("out.xml");

        pos = new XMLPos(doc);

//      if (pos.go("get_packets/packet"))
//      if (pos.go("/get_packets/packet"))
//      if (pos.go("/get_packets/packet[5]"))
        if (pos.go("/get_packets/packet[@db_id=\"7628\"]"))
//      if (pos.go("get_machines/machine[@wsid=\"client2\"]"))
        {

            pos.back();
        }
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.test2Read (  ) throws Exception

Read back the example file and print some of its content.

Exceptions:
Exception

Definition at line 163 of file XMLTest.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.XMLTest.main().

    {
        XMLDoc doc = new XMLDoc();

         // Einlesen des XML-Files
        doc.readFile("sandra1.xml");

        XMLPos pos = new XMLPos(doc);
        String filename = "";
        int size = 0;

         // Abfrage eines Elementinhalts, beispielsweise von FONT_FILENAME
        if (pos.go("PARAMS/FONT")) {
            if (pos.goDown("FONT_FILENAME")) {
                filename = pos.getContent();
                pos.back();
            }

            if (pos.goDown("SIZE")) {
                size = new XMLInt(pos.getContent()).intValue();
                pos.back();
            }

            pos.back();
        }

         // Ausgabe des ermittelten Werts
        System.out.println("font filename: " + filename);
        System.out.println("font size: " + size);

        assertEquals("Font filename", "Arial.ttf", filename);
        assertEquals("Font size", 12, size);
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.test2Write (  ) throws Exception

Write an example XML file.

Exceptions:
Exception

Definition at line 119 of file XMLTest.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.XMLTest.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");
          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("sandra1.xml");
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.test3Write (  ) throws Exception

Test 3 of XMLStorage: write another example file.

Exceptions:
Exception

Definition at line 202 of file XMLTest.java.

References de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.create(), de.mfuchs.xmlstorage.XMLPos.put(), de.mfuchs.xmlstorage.XMLPos.setContent(), and de.mfuchs.xmlstorage.XMLDoc.writeFile().

Referenced by de.mfuchs.XMLTest.main().

    {
        XMLDoc doc = new XMLDoc();
        XMLPos pos = new XMLPos(doc);

         // create the XML tree in memory
        pos.create("root");

          pos.create("foo");
            pos.setContent("bar");
          pos.back(); // </foo>

          pos.create("foo2");
            pos.put("attr1", "value1");
            pos.put("attr2", "value2");

            pos.create("foo3");
            pos.setContent("bar2");
            pos.back();
          pos.back();

        pos.back(); // </root>

         // write the XML file
        doc.writeFile("test.xml");
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.testStreamingReader1 (  ) throws Exception

Stream test 1 for XMLStreamReader.

Exceptions:
Exception

Definition at line 234 of file XMLTest.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.back(), de.mfuchs.xmlstorage.stream.XMLStreamReader.close(), de.mfuchs.xmlstorage.stream.XMLStreamReader.firstChild(), de.mfuchs.xmlstorage.stream.XMLStreamReader.get(), de.mfuchs.xmlstorage.stream.XMLStreamReader.getNode(), de.mfuchs.xmlstorage.stream.XMLStreamReader.goDown(), de.mfuchs.xmlstorage.XMLInt.intValue(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.nextSkipOthers().

Referenced by de.mfuchs.XMLTest.main().

    {
        String path = "packets.xml";

        XMLStreamReader reader = new XMLStreamReader(path);

        reader.goDown("get_packets");

        if (reader.firstChild("packet")) do {
            XMLInt dbId = new XMLInt(reader, "db_id");
            System.out.println("db_id: " + dbId.intValue());

            int x = reader.getNode().getInt("db_id", 12345).intValue();
            System.out.println("x: " + x);

            System.out.println(reader + " \"" + reader.get("name") + "\"");
        } while(reader.nextSkipOthers("packet"));

        reader.back();

        reader.close();
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.testStreamingReader2 (  ) throws Exception

Stream test 2 for XMLStreamReader.

Exceptions:
Exception

Definition at line 289 of file XMLTest.java.

References de.mfuchs.xmlstorage.stream.XMLStreamReader.back(), de.mfuchs.xmlstorage.stream.XMLStreamReader.close(), de.mfuchs.xmlstorage.stream.XMLStreamReader.get(), de.mfuchs.xmlstorage.stream.XMLStreamReader.getContent(), and de.mfuchs.xmlstorage.stream.XMLStreamReader.goDown().

Referenced by de.mfuchs.XMLTest.main().

    {
        String path = "stream-example.xml";

        XMLStreamReader reader = new XMLStreamReader(path);

        if (reader.goDown("PERSON")) {
            if (reader.goDown("NAME")) {
                String content = reader.getContent();
                System.out.println("NAME content=" + content);

                reader.back(); // </NAME>
            }

            if (reader.goDown("VORNAME")) {
                String content = reader.getContent();
                System.out.println("VORNAME content=" + content);

                reader.back(); // </VORNAME>
            }
        }

        if (reader.goDown("ADRESSE")) {
            String priv = reader.get("private");
            String content = reader.getContent();
            System.out.println("ADRESSE.@private=" + priv);
            System.out.println("ADRESSE content=" + content);

            reader.back(); // </ADRESSE>
        }

        reader.back(); // </PERSON>

        reader.close();
    }

Here is the call graph for this function:

void de.mfuchs.XMLTest.testStreamingWriter (  ) throws Exception

Stream test for XMLStreamWriter.

Exceptions:
Exception

Definition at line 261 of file XMLTest.java.

References de.mfuchs.xmlstorage.stream.XMLStreamWriter.back(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.close(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.create(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.put(), and de.mfuchs.xmlstorage.stream.XMLStreamWriter.setContent().

    {
        XMLStreamWriter writer = new XMLStreamWriter("stream-example.xml");

        writer.create("PERSON");

          writer.create("NAME");
            writer.setContent("Mustername");
          writer.back(); // </NAME>

          writer.create("VORNAME");
            writer.setContent("Mustervorname");
          writer.back(); // </VORNAME>

          writer.create("ADRESSE");
            writer.put("private", new XMLBool(true));
            writer.setContent("Musteradresse");
          writer.back(); // </ADRESSE>

        writer.back(); // </PERSON>

        writer.close();
    }

Here is the call graph for this function:


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