    
    
/*
    
    LMXP - a small XML parser written in pure JAVA 
    Copyright (C) 2003  Michael Bayer <nsn@nightspawn.com>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
*/


package de.nightspawn.lmxp;

import java.util.*;

/**
    a document conainer 
 */
public class LMXPDocument extends LMXPNode {

    private                     LMXPVersion                     Version = new LMXPVersion();
    private                     LMXPDocType                     DocType = new LMXPDocType();

    /**
        creates a new, empty document
     */
    public LMXPDocument() {
    }

    public LMXPNode getRootNode() {
        return this.getChildNode(0);
    }

    /**
        sets the version container
     */
    public void setVersion(LMXPVersion v) {
        this.Version = v;
        this.Version.setParent(this);
    }

    /**
        returns the version container
     */
    public LMXPVersion getVersion() {
        return this.Version;
    }

    /**
        sets the DocType container
     */
    public void setDocType(LMXPDocType v) {
        this.DocType = v;
        this.DocType.setParent(this);
    }

    /**
        returns the DocType container
     */
    public LMXPDocType getDocType() {
        return this.DocType;
    }

    /**
        returns an XML String representing this Document
     */
    public String toXML() {
        return this.toXML(0);
    }

    /**
        returns an XML String representing this Document
     */
    public String toXML(int id) {
        String pre = this.getPre(id);
        String xml = new String();
        xml = xml.concat(pre+this.getVersion().toXML());
        xml = xml.concat(pre+this.getDocType().toXML());
        LMXPNode[] children = this.getChildNodes();
        if (children.length != 0) {
            for (int i=0;i<children.length;i++) {
                xml = xml.concat(children[i].toXML(id));
            }
        }
        return xml;
    }

    /**
        prints a crude view on this document
     */
    public void printTree() {
        super.printTree(0);
    }

}
