Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.jdom.Document
public class Document
extends java.lang.Object
implements Serializable, Cloneable
Document
defines behavior for an XML Document, modeled
in Java. Methods allow access to the root element as well
as processing instructions and other document-level information.
Field Summary | |
protected org.jdom.ContentList |
|
protected DocType |
Constructor Summary | |
| |
Method Summary | |
Document |
|
Document |
|
Object |
|
Element |
|
boolean |
|
List |
|
List |
|
DocType |
|
Element |
|
boolean |
|
int |
|
boolean |
|
boolean |
|
Document |
|
Document |
|
Document |
|
String |
|
public Document()
Creates a new empty document. A document must have a root element, so this document will not be well-formed and accessor methods will throw an IllegalStateException if this document is accessed before a root element is added. This method is most useful for build tools.
public Document(List content)
This will create a newDocument
, with the supplied list of content, and nodeclaration.
DocType
- Parameters:
content
-List
of starter content
public Document(List newContent, DocType docType)
This will create a newDocument
, with the supplied list of content, and the supplieddeclaration.
DocType
- Parameters:
docType
-DocType
declaration.
public Document(Element rootElement)
This will create a newDocument
, with the suppliedas the root element, and no
Element
declaration.
DocType
- Parameters:
rootElement
-Element
for document root
public Document addContent(Comment comment)
This will add a comment to theDocument
.
- Parameters:
comment
-Comment
to add.
- Returns:
Document
- this object modified.
public Document addContent(ProcessingInstruction pi)
Adds the specified PI to the document.
- Parameters:
pi
- the ProcessingInstruction to add.
- Returns:
Document
this document modified.
public Object clone()
This will return a deep clone of thisDocument
.
- Returns:
Object
- clone of thisDocument
.
public Element detachRootElement()
Detach the rootfrom this document.
Element
- Returns:
- removed root
Element
public final boolean equals(Object ob)
This tests for equality of thisDocument
to the suppliedObject
.
- Parameters:
ob
-Object
to compare to.
- Returns:
boolean
- whether theDocument
is equal to the suppliedObject
.
public List getContent()
This will return all content for theDocument
. The returned list is "live" in document order and changes to it affect the document's actual content. Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may require walking the entire list.
- Returns:
List
- all Document content
public List getContent(Filter filter)
Return a filtered view of thisDocument
's content. Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may require walking the entire list.
- Parameters:
filter
-Filter
to apply
- Returns:
List
- filtered Document content
public Element getRootElement()
This will return the rootElement
for thisDocument
- Returns:
Element
- the document's root element
public boolean hasRootElement()
This will returntrue
if this document has a root element,false
otherwise.
- Returns:
true
if this document has a root element,false
otherwise.
public final int hashCode()
This returns the hash code for thisDocument
.
- Returns:
int
- hash code.
public boolean removeContent(Comment comment)
This removes the specifiedComment
. If the specifiedComment
is not a child of thisDocument
, this method does nothing.
- Parameters:
comment
-Comment
to delete
- Returns:
- whether deletion occurred
public boolean removeContent(ProcessingInstruction pi)
This removes the specifiedProcessingInstruction
. If the specifiedProcessingInstruction
is not a child of thisDocument
, this method does nothing.
- Parameters:
- Returns:
- whether deletion occurred
public Document setContent(List newContent)
This sets the content of theDocument
. The supplied List should contain only objects of typeElement
,Comment
, andProcessingInstruction
. When all objects in the supplied List are legal and before the new content is added, all objects in the old content will have their parentage set to null (no parent) and the old content list will be cleared. This has the effect that any active list (previously obtained with a call togetContent
) will also change to reflect the new content. In addition, all objects in the supplied List will have their parentage set to this document, but the List itself will not be "live" and further removals and additions will have no effect on this document content. If the user wants to continue working with a "live" list, then a call to setContent should be followed by a call togetContent
to obtain a "live" version of the content. Passing a null or empty List clears the existing content. In event of an exception the original content will be unchanged and the objects in the supplied content will be unaltered.
- Returns:
- this document modified
public Document setDocType(DocType docType)
This will set thedeclaration for this
DocType
Document
. Note that a DocType can only be attached to one Document. Attempting to set the DocType to a DocType object that already belongs to a Document will result in an IllegalAddException being thrown.
- Parameters:
docType
-DocType
declaration.
public Document setRootElement(Element rootElement)
This sets the rootfor the
Element
Document
. If the document already has a root element, it is replaced.
- Parameters:
rootElement
-Element
to be new root.
- Returns:
Document
- modified Document.
public String toString()
This returns aString
representation of theDocument
, suitable for debugging. If the XML representation of theDocument
is desired,XMLOutputter.outputString(Document)
should be used.
- Returns:
String
- information about theDocument