Package com.ociweb.xml

Examples of com.ociweb.xml.WAX


public class CDDemo2 {

    public static void main(String[] args) {
        // Write to stdout with an XML declaration that specifies version 1.0.
        // If the version is omitted then no XML declaration will be written.
        PrologWAX pw = (PrologWAX) new WAX(Version.V1_0);

        pw.dtd("http://www.ociweb.com/xml/music.dtd");
        pw.xslt("artist.xslt");

        StartTagWAX stw = pw.start("artist");
View Full Code Here


    public static void main(String[] args) {
        // When the no-arg WAX constructor is used, XML is written to stdout.
        // There are also WAX constructors that take
        // a java.io.OutputStream and a java.io.Writer object.
        WAX wax = new WAX();

        out("Only a root element:");
        wax.start("car").close();
        // <car/>

        // After a WAX object is closed,
        // a new one must be created to write more XML.
        wax = new WAX();

        out("A root element with some text inside:");
        wax.start("car").text("Prius").close();
        // <car>Prius</car>

        out("Text inside a child element:");
        wax = new WAX();
        wax.start("car").start("model").text("Prius").close();
        // <car>
        //   <model>Prius</model>
        // </car>

        out("The same with the \"child\" convenience method:");
        wax = new WAX();
        wax.start("car").child("model", "Prius").close();
        // <car>
        //   <model>Prius</model>
        // </car>

        out("Text in a CDATA section:");
        wax = new WAX();
        wax.start("car").start("model").cdata("1<2>3&4'5\"6").close();
        // <car>
        //   <model>
        //     <![CDATA[1<2>3&4'5\"6]]>
        //   </model>
        // </car>

        out("Without indentation, on a single line:");
        wax = new WAX();
        wax.noIndentsOrLineSeparators();
        wax.start("car").child("model", "Prius").close();
        // <car><model>Prius</model></car>

        out("Indent with four spaces instead of the default of two:");
        wax = new WAX();
        wax.setIndent("    ");
        wax.start("car").child("model", "Prius").close();
        // <car>
        //     <model>Prius</model>
        // </car>

        out("Add an attribute:");
        wax = new WAX();
        wax.start("car").attr("year", 2008).child("model", "Prius").close();
        // <car year="2008">
        //   <model>Prius</model>
        // </car>

        out("XML declaration:");
        wax = new WAX(Version.V1_0);
        wax.start("car").attr("year", 2008)
           .child("model", "Prius").close();
        // <?xml version="1.0" encoding="UTF-8"?>
        // <car year="2008">
        //   <model>Prius</model>
        // </car>

        out("Comment:");
        wax = new WAX();
        wax.comment("This is a hybrid car.")
           .start("car").child("model", "Prius").close();
        // <!-- This is a hybrid car. -->
        // <car>
        //   <model>Prius</model>
        // </car>

        out("Processing instruction:");
        wax = new WAX();
        wax.processingInstruction("target", "data")
            .start("car").attr("year", 2008)
           .child("model", "Prius").close();
        // <?target data?>
        // <car year="2008">
        //   <model>Prius</model>
        // </car>

        out("Associate an XSLT stylesheet:");
        wax = new WAX();
        wax.xslt("car.xslt")
           .start("car").attr("year", 2008)
           .child("model", "Prius").close();
        // <?xml-stylesheet type="text/xsl" href="car.xslt"?>
        // <car year="2008">
        //   <model>Prius</model>
        // </car>

        out("Associate a default namespace:");
        wax = new WAX();
        wax.start("car").attr("year", 2008)
           .defaultNamespace("http://www.ociweb.com/cars")
           .child("model", "Prius").close();
        // <car year="2008"
        //   xmlns="http://www.ociweb.com/cars">
        //   <model>Prius</model>
        // </car>

        out("Associate a non-default namespace with the XML:");
        wax = new WAX();
        String prefix = "c";
        wax.start(prefix, "car").attr("year", 2008)
           .namespace(prefix, "http://www.ociweb.com/cars")
           .child(prefix, "model", "Prius").close();
        // <c:car year="2008"
        //   xmlns:c="http://www.ociweb.com/cars">
        //   <c:model>Prius</c:model>
        // </c:car>

        out("Associate an XML Schema:");
        wax = new WAX();
        wax.start("car").attr("year", 2008)
           .defaultNamespace("http://www.ociweb.com/cars", "car.xsd")
           .child("model", "Prius").close();
        // <car year="2008"
        //   xmlns="http://www.ociweb.com/cars"
        //   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        //   xsi:schemaLocation="http://www.ociweb.com/cars car.xsd">
        //   <model>Prius</model>
        // </car>

        out("Associate multiple XML Schemas:");
        wax = new WAX();
        wax.start("car").attr("year", 2008)
           .defaultNamespace("http://www.ociweb.com/cars", "car.xsd")
           .namespace("m", "http://www.ociweb.com/model", "model.xsd")
           .child("m", "model", "Prius").close();
        // <car year="2008"
        //   xmlns="http://www.ociweb.com/cars"
        //   xmlns:m="http://www.ociweb.com/model"
        //   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        //   xsi:schemaLocation="http://www.ociweb.com/cars car.xsd
        //     http://www.ociweb.com/model model.xsd">
        //   <m:model>Prius</m:model>
        // </car>

        out("Associate a DTD:");
        wax = new WAX();
        wax.dtd("car.dtd")
           .start("car").attr("year", 2008)
           .child("model", "Prius").close();
        // <!DOCTYPE car SYSTEM "car.dtd">
        // <car year="2008">
        //   <model>Prius</model>
        // </car>

        out("Entity definitions in DOCTYPE:");
        String url = "http://www.ociweb.com/xml/";
        wax = new WAX();
        wax.entityDef("oci", "Object Computing, Inc.")
           .externalEntityDef("moreData", url + "moreData.xml")
           .start("root")
           .unescapedText("The author works at &oci; in St. Louis, Missouri.", true)
           .unescapedText("&moreData;", true)
           .close();
        //<!DOCTYPE root [
        //  <!ENTITY oci "Object Computing, Inc.">
        //  <!ENTITY moreData SYSTEM "http://www.ociweb.com/xml/moreData.xml">
        //>
        //<root>
        //  The author works at &oci; in St. Louis, Missouri.
        //  &moreData;
        //</root>

        out("Default indentation - text and comment:");
        wax = new WAX();
        wax.start("foo").text("bar").comment("baz").close();

        out("Default indentation - text and cdata:");
        wax = new WAX();
        wax.start("foo").text("bar").cdata("baz").close();
    }
View Full Code Here

public class CDDemo3 {

    public static void main(String[] args) {
        // Write to stdout with an XML declaration that specifies version 1.0.
        // If the version is omitted then no XML declaration will be written.
        WAX wax = new WAX(Version.V1_0);

        wax.xslt("artist.xslt");
        wax.dtd("http://www.ociweb.com/xml/music.dtd");

        wax.start("artist");
        wax.attr("name", "Gardot, Melody");
        wax.defaultNamespace("http://www.ociweb.com/music",
            "http://www.ociweb.com/xml/music.xsd");
        wax.namespace("date", "http://www.ociweb.com/date",
            "http://www.ociweb.com/xml/date.xsd");

        wax.comment("This is one of my favorite CDs!");
        wax.start("cd");
        wax.attr("year", 2007);

        wax.child("title", "Worrisome Heart");
        wax.child("date", "purchaseDate", "4/3/2008");

        wax.close(); // terminates all unterminated elements
    }
View Full Code Here

    public static void main(String[] args) {
        // Write to System.out with an XML declaration
        // that specifies version 1.0.
        // If the version is omitted then no XML declaration will be written.
        WAX wax = new WAX(Version.V1_0);

        wax.xslt("artist.xslt")
           .dtd("http://www.ociweb.com/xml/music.dtd")
           .start("artist")
           .attr("name", "Gardot, Melody")
           .defaultNamespace("http://www.ociweb.com/music",
               "http://www.ociweb.com/xml/music.xsd")
View Full Code Here

TOP

Related Classes of com.ociweb.xml.WAX

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.