| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectorg.jdom.Documentpublic class Documentextends java.lang.Objectimplements Serializable, CloneableDocument 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-Listof 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-DocTypedeclaration.
public Document(Element rootElement)
This will create a newDocument, with the suppliedas the root element, and noElementdeclaration.DocType
- Parameters:
rootElement-Elementfor document root
public Document addContent(Comment comment)
This will add a comment to theDocument.
- Parameters:
comment-Commentto 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:
Documentthis 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 thisDocumentto the suppliedObject.
- Parameters:
ob-Objectto compare to.
- Returns:
boolean- whether theDocumentis 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-Filterto apply
- Returns:
List- filtered Document content
public Element getRootElement()
This will return the rootElementfor thisDocument
- Returns:
Element- the document's root element
public boolean hasRootElement()
This will returntrueif this document has a root element,falseotherwise.
- Returns:
trueif this document has a root element,falseotherwise.
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 specifiedCommentis not a child of thisDocument, this method does nothing.
- Parameters:
comment-Commentto delete
- Returns:
- whether deletion occurred
public boolean removeContent(ProcessingInstruction pi)
This removes the specifiedProcessingInstruction. If the specifiedProcessingInstructionis 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 togetContentto 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 thisDocTypeDocument. 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-DocTypedeclaration.
public Document setRootElement(Element rootElement)
This sets the rootfor theElementDocument. If the document already has a root element, it is replaced.
- Parameters:
rootElement-Elementto be new root.
- Returns:
Document- modified Document.
public String toString()
This returns aStringrepresentation of theDocument, suitable for debugging. If the XML representation of theDocumentis desired,XMLOutputter.outputString(Document)should be used.
- Returns:
String- information about theDocument