FileDocCategorySizeDatePackage
Document.javaAPI DocAndroid 1.5 API4018Wed May 06 22:41:06 BST 2009org.kxml2.kdom

Document

public class Document extends Node
The document consists of some legacy events and a single root element. This class basically adds some consistency checks to Node.

Fields Summary
protected int
rootIndex
String
encoding
Boolean
standalone
Constructors Summary
Methods Summary
public voidaddChild(int index, int type, java.lang.Object child)
Adds a child at the given index position. Throws an exception when a second root element is added

        if (type == ELEMENT) {
         //   if (rootIndex != -1)
           //     throw new RuntimeException("Only one document root element allowed");

            rootIndex = index;
        }
        else if (rootIndex >= index)
            rootIndex++;

        super.addChild(index, type, child);
    
public java.lang.StringgetEncoding()
returns "#document"


       

        
        return encoding;
    
public java.lang.StringgetName()

        return "#document";
    
public org.kxml2.kdom.ElementgetRootElement()
returns the root element of this document.

        if (rootIndex == -1)
            throw new RuntimeException("Document has no root element!");

        return (Element) getChild(rootIndex);
    
public java.lang.BooleangetStandalone()

        return standalone;
    
public voidparse(org.xmlpull.v1.XmlPullParser parser)
reads the document and checks if the last event is END_DOCUMENT. If not, an exception is thrown. The end event is consumed. For parsing partial XML structures, consider using Node.parse ().


        parser.require(XmlPullParser.START_DOCUMENT, null, null);
        parser.nextToken ();            

        encoding = parser.getInputEncoding();
        standalone = (Boolean)parser.getProperty ("http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone");
        
        super.parse(parser);

        if (parser.getEventType() != XmlPullParser.END_DOCUMENT)
            throw new RuntimeException("Document end expected!");

    
public voidremoveChild(int index)

        if (index == rootIndex)
            rootIndex = -1;
        else if (index < rootIndex)
            rootIndex--;

        super.removeChild(index);
    
public voidsetEncoding(java.lang.String enc)

        this.encoding = enc;
    
public voidsetStandalone(java.lang.Boolean standalone)

        this.standalone = standalone;
    
public voidwrite(org.xmlpull.v1.XmlSerializer writer)
Writes this node to the given XmlWriter. For node and document, this method is identical to writeChildren, except that the stream is flushed automatically.

        
        writer.startDocument(encoding, standalone);
        writeChildren(writer);
        writer.endDocument();