/*
 * (C) Copyright IBM Corp. 1997-1998  All rights reserved.
 *
 * US Government Users Restricted Rights Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * IBM will not be liable for any damages suffered by you as a result
 * of using the Program. In no event will IBM be liable for any
 * special, indirect or consequential damages or lost profits even if
 * IBM has been advised of the possibility of their occurrence. IBM
 * will not be liable for any third party claims against you.
 */

package com.ibm.xml.sample;

import com.ibm.xml.parser.*;
import java.io.*;

/**
 *
 * @version 1.1
 * @author TAMURA Kent &lt;kent@trl.ibm.co.jp&gt;
 */
public class SimpleGen {
    public static void main(String[] argv) {
        try {
            ElementFactory ef = new DefaultElementFactory();

            TXDocument doc = ef.createDocument();
            doc.setVersion("1.0");
            DTD dtd = ef.createDTD("ROOT", null);
                                        // Make <!ENTITY chapter1 SYSTEM "chap1.ent">
            dtd.addElement(ef.createEntity("chapter1", new ExternalID("chap1.ent"), false, null));
                                        // Make <!ELEMENT ROOT (#PCDATA)>
            dtd.addElement(ef.createElementDecl("ROOT", ef.createContentModel(new CMLeaf("#PCDATA"))));
            doc.addElement(dtd);

            TXElement root = ef.createElement("ROOT");
            root.addElement(ef.createGeneralReference("chapter1"));
            doc.addElement(root);

            doc.printWithFormat(new PrintWriter(System.out));

            System.out.println("================================================================");
                                                // Another way
            doc = ef.createDocument();
            doc.setVersion("1.0");
            dtd = ef.createDTD("ROOT", null);
            dtd.addElement(new PseudoNode("<!ENTITY chapter1 SYSTEM \"chap1.ent\">"));
            dtd.addElement(new PseudoNode("<!ELEMENT ROOT (#PCDATA)>"));
            doc.addElement(dtd);
            root = ef.createElement("ROOT");
            root.addElement(new PseudoNode("&chapter1;"));
            doc.addElement(root);

            doc.printWithFormat(new PrintWriter(System.out));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
