All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----org.jdom.Document
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.
Document
's
{
-
docType
- The
{
Creates a new empty document.
This will create a new
This will create a new
This will create a new
This will create a new Document
,
with the supplied {
Document(Element, DocType)
Document
,
with the supplied {
Document(List)
Document
,
with the supplied list of content, and no
{
Document(List, DocType)
Document
,
with the supplied list of content, and the supplied
{
This will add a comment to the Document
.
Adds the specified PI to the document.
This will return a deep clone of this Document
.
Detach the root
This tests for equality of this
This will return all content for the
Return a filtered view of this
This will return the
This will return the root
This returns the hash code for this
This will return
This removes the specified
This removes the specified
This sets the content of the
This will set the
This sets the root
This returns a {
equals(Object)
Document
to the supplied
Object
.
getContent()
Document
.
getContent(Filter)
Document
's content.
getDocType()
{
getRootElement()
Element
for this Document
hashCode()
Document
.
hasRootElement()
true
if this document has a
root element, false
otherwise.
removeContent(Comment)
Comment
.
removeContent(ProcessingInstruction)
ProcessingInstruction
.
setContent(List)
Document
.
setDocType(DocType)
{
setRootElement(Element)
{
toString()
String
representation of the
Document
, suitable for debugging.
protected ContentList content
Document
's
{@link Comment}
s,
{@link ProcessingInstruction}
s and
the root {@link Element}
.
protected DocType docType
{@link DocType}
declaration.
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(Element rootElement, DocType docType)
This will create a new Document
,
with the supplied {@link Element}
as the root element and the supplied
{@link DocType}
declaration.
Element
for document root.
DocType
declaration.
public Document(Element rootElement)
This will create a new Document
,
with the supplied {@link Element}
as the root element, and no {@link DocType}
declaration.
Element
for document root
public Document(List newContent, DocType docType)
This will create a new Document
,
with the supplied list of content, and the supplied
{@link DocType}
declaration.
List
of starter content
DocType
declaration.
public Document(List content)
This will create a new Document
,
with the supplied list of content, and no
{@link DocType}
declaration.
List
of starter content
public boolean hasRootElement()
This will return true
if this document has a
root element, false
otherwise.
true
if this document has a root element,
false
otherwise.
public Element getRootElement()
This will return the root Element
for this Document
Element
- the document's root element
public Document setRootElement(Element rootElement)
This sets the root {@link Element}
for the
Document
. If the document already has a root
element, it is replaced.
Element
to be new root.
Document
- modified Document.
public Element detachRootElement()
Detach the root {@link Element}
from this document.
Element
public DocType getDocType()
This will return the {@link DocType}
declaration for this Document
, or
null
if none exists.
DocType
- the DOCTYPE declaration.
public Document setDocType(DocType docType)
This will set the {@link DocType}
declaration for this 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.
DocType
declaration.
public Document addContent(ProcessingInstruction pi)
Adds the specified PI to the document.
Document
this document modified.
public Document addContent(Comment comment)
This will add a comment to the Document
.
Comment
to add.
Document
- this object modified.
public List getContent()
This will return all content for the Document
.
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.
List
- all Document content
public List getContent(Filter filter)
Return a filtered view of this Document
'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.
Filter
to apply
List
- filtered Document content
public Document setContent(List newContent)
This sets the content of the Document
. The supplied
List should contain only objects of type Element
,
Comment
, and ProcessingInstruction
.
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 to {@link #getContent}) 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 to {@link #getContent} 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.
public boolean removeContent(ProcessingInstruction pi)
This removes the specified ProcessingInstruction
.
If the specified ProcessingInstruction
is not a child of
this Document
, this method does nothing.
ProcessingInstruction
to delete
public boolean removeContent(Comment comment)
This removes the specified Comment
.
If the specified Comment
is not a child of
this Document
, this method does nothing.
Comment
to delete
public String toString()
This returns a String
representation of the
Document
, suitable for debugging. If the XML
representation of the Document
is desired,
{@link org.jdom.output.XMLOutputter#outputString(Document)}
should be used.
String
- information about the
Document
public final boolean equals(Object ob)
This tests for equality of this Document
to the supplied
Object
.
Object
to compare to.
boolean
- whether the Document
is
equal to the supplied Object
.
public final int hashCode()
This returns the hash code for this Document
.
int
- hash code.
public Object clone()
This will return a deep clone of this Document
.
Object
- clone of this Document
.
All Packages Class Hierarchy This Package Previous Next Index