Document.pod 5.5 KB
Newer Older
Z
zhanghan17 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
=head1 NAME

XML::DOM::Document - An XML document node in XML::DOM

=head1 DESCRIPTION

XML::DOM::Document extends L<XML::DOM::Node>.

It is the main root of the XML document structure as returned by 
XML::DOM::Parser::parse and XML::DOM::Parser::parsefile.

Since elements, text nodes, comments, processing instructions, etc.
cannot exist outside the context of a Document, the Document interface
also contains the factory methods needed to create these objects. The
Node objects created have a getOwnerDocument method which associates
them with the Document within whose context they were created.

=head2 METHODS

=over 4

=item getDocumentElement

This is a convenience method that allows direct access to
the child node that is the root Element of the document.

=item getDoctype

The Document Type Declaration (see DocumentType) associated
with this document. For HTML documents as well as XML
documents without a document type declaration this returns
undef. The DOM Level 1 does not support editing the Document
Type Declaration.

B<Not In DOM Spec>: This implementation allows editing the doctype. 
See I<XML::DOM::ignoreReadOnly> for details.

=item getImplementation

The DOMImplementation object that handles this document. A
DOM application may use objects from multiple implementations.

=item createElement (tagName)

Creates an element of the type specified. Note that the
instance returned implements the Element interface, so
attributes can be specified directly on the returned object.

DOMExceptions:

=over 4

=item * INVALID_CHARACTER_ERR

Raised if the tagName does not conform to the XML spec.

=back

=item createTextNode (data)

Creates a Text node given the specified string.

=item createComment (data)

Creates a Comment node given the specified string.

=item createCDATASection (data)

Creates a CDATASection node given the specified string.

=item createAttribute (name [, value [, specified ]])

Creates an Attr of the given name. Note that the Attr
instance can then be set on an Element using the setAttribute method.

B<Not In DOM Spec>: The DOM Spec does not allow passing the value or the 
specified property in this method. In this implementation they are optional.

Parameters:
 I<value>     The attribute's value. See Attr::setValue for details.
              If the value is not supplied, the specified property is set to 0.
 I<specified> Whether the attribute value was specified or whether the default
              value was used. If not supplied, it's assumed to be 1.

DOMExceptions:

=over 4

=item * INVALID_CHARACTER_ERR

Raised if the name does not conform to the XML spec.

=back

=item createProcessingInstruction (target, data)

Creates a ProcessingInstruction node given the specified name and data strings.

Parameters:
 I<target>  The target part of the processing instruction.
 I<data>    The data for the node.

DOMExceptions:

=over 4

=item * INVALID_CHARACTER_ERR

Raised if the target does not conform to the XML spec.

=back

=item createDocumentFragment

Creates an empty DocumentFragment object.

=item createEntityReference (name)

Creates an EntityReference object.

=back

=head2 Additional methods not in the DOM Spec

=over 4

=item getXMLDecl and setXMLDecl (xmlDecl)

Returns the XMLDecl for this Document or undef if none was specified.
Note that XMLDecl is not part of the list of child nodes.

=item setDoctype (doctype)

Sets or replaces the DocumentType. 
B<NOTE>: Don't use appendChild or insertBefore to set the DocumentType.
Even though doctype will be part of the list of child nodes, it is handled
specially.

=item getDefaultAttrValue (elem, attr)

Returns the default attribute value as a string or undef, if none is available.

Parameters:
 I<elem>    The element tagName.
 I<attr>    The attribute name.

=item getEntity (name)

Returns the Entity with the specified name.

=item createXMLDecl (version, encoding, standalone)

Creates an XMLDecl object. All parameters may be undefined.

=item createDocumentType (name, sysId, pubId)

Creates a DocumentType object. SysId and pubId may be undefined.

=item createNotation (name, base, sysId, pubId)

Creates a new Notation object. Consider using 
XML::DOM::DocumentType::addNotation!

=item createEntity (parameter, notationName, value, sysId, pubId, ndata)

Creates an Entity object. Consider using XML::DOM::DocumentType::addEntity!

=item createElementDecl (name, model)

Creates an ElementDecl object.

DOMExceptions:

=over 4

=item * INVALID_CHARACTER_ERR

Raised if the element name (tagName) does not conform to the XML spec.

=back

=item createAttlistDecl (name)

Creates an AttlistDecl object.

DOMExceptions:

=over 4

=item * INVALID_CHARACTER_ERR

Raised if the element name (tagName) does not conform to the XML spec.

=back

=item expandEntity (entity [, parameter])

Expands the specified entity or parameter entity (if parameter=1) and returns
its value as a string, or undef if the entity does not exist.
(The entity name should not contain the '%', '&' or ';' delimiters.)

=item check ( [$checker] )

Uses the specified L<XML::Checker> to validate the document.
If no XML::Checker is supplied, a new XML::Checker is created.
See L<XML::Checker> for details.

=item check_sax ( [$checker] )

Similar to check() except it uses the SAX interface to XML::Checker instead of 
the expat interface. This method may disappear or replace check() at some time.

=item createChecker ()

Creates an XML::Checker based on the document's DTD.
The $checker can be reused to check any elements within the document.
Create a new L<XML::Checker> whenever the DOCTYPE section of the document 
is altered!

=back