655
|
1 |
=head1 NAME
|
|
2 |
|
|
3 |
XML::DOM::DocumentFragment - Facilitates cut & paste in XML::DOM documents
|
|
4 |
|
|
5 |
=head1 DESCRIPTION
|
|
6 |
|
|
7 |
XML::DOM::DocumentFragment extends L<XML::DOM::Node>
|
|
8 |
|
|
9 |
DocumentFragment is a "lightweight" or "minimal" Document object. It is
|
|
10 |
very common to want to be able to extract a portion of a document's
|
|
11 |
tree or to create a new fragment of a document. Imagine implementing a
|
|
12 |
user command like cut or rearranging a document by moving fragments
|
|
13 |
around. It is desirable to have an object which can hold such fragments
|
|
14 |
and it is quite natural to use a Node for this purpose. While it is
|
|
15 |
true that a Document object could fulfil this role, a Document object
|
|
16 |
can potentially be a heavyweight object, depending on the underlying
|
|
17 |
implementation. What is really needed for this is a very lightweight
|
|
18 |
object. DocumentFragment is such an object.
|
|
19 |
|
|
20 |
Furthermore, various operations -- such as inserting nodes as children
|
|
21 |
of another Node -- may take DocumentFragment objects as arguments; this
|
|
22 |
results in all the child nodes of the DocumentFragment being moved to
|
|
23 |
the child list of this node.
|
|
24 |
|
|
25 |
The children of a DocumentFragment node are zero or more nodes
|
|
26 |
representing the tops of any sub-trees defining the structure of the
|
|
27 |
document. DocumentFragment nodes do not need to be well-formed XML
|
|
28 |
documents (although they do need to follow the rules imposed upon
|
|
29 |
well-formed XML parsed entities, which can have multiple top nodes).
|
|
30 |
For example, a DocumentFragment might have only one child and that
|
|
31 |
child node could be a Text node. Such a structure model represents
|
|
32 |
neither an HTML document nor a well-formed XML document.
|
|
33 |
|
|
34 |
When a DocumentFragment is inserted into a Document (or indeed any
|
|
35 |
other Node that may take children) the children of the DocumentFragment
|
|
36 |
and not the DocumentFragment itself are inserted into the Node. This
|
|
37 |
makes the DocumentFragment very useful when the user wishes to create
|
|
38 |
nodes that are siblings; the DocumentFragment acts as the parent of
|
|
39 |
these nodes so that the user can use the standard methods from the Node
|
|
40 |
interface, such as insertBefore() and appendChild().
|