deprecated/buildtools/buildsystemtools/lib/XML/DOM/Element.pod
author jascui
Tue, 16 Nov 2010 15:56:27 +0800
changeset 683 8e0eb519ef53
parent 655 3f65fd25dfd4
permissions -rw-r--r--
Solve incorrect handling of ExportName=SymbolName@Ordinal syntax
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
=head1 NAME
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
XML::DOM::Element - An XML element node in XML::DOM
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
=head1 DESCRIPTION
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
XML::DOM::Element extends L<XML::DOM::Node>.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
By far the vast majority of objects (apart from text) that authors
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
encounter when traversing a document are Element nodes. Assume the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
following XML document:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
     <elementExample id="demo">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
       <subelement1/>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
       <subelement2><subsubelement/></subelement2>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
     </elementExample>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
When represented using DOM, the top node is an Element node for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
"elementExample", which contains two child Element nodes, one for
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
"subelement1" and one for "subelement2". "subelement1" contains no
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
child nodes.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
Elements may have attributes associated with them; since the Element
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
interface inherits from Node, the generic Node interface method
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
getAttributes may be used to retrieve the set of all attributes for an
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
element. There are methods on the Element interface to retrieve either
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
an Attr object by name or an attribute value by name. In XML, where an
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
attribute value may contain entity references, an Attr object should be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
retrieved to examine the possibly fairly complex sub-tree representing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
the attribute value. On the other hand, in HTML, where all attributes
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
have simple string values, methods to directly access an attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
value can safely be used as a convenience.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
=head2 METHODS
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
=item getTagName
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
The name of the element. For example, in:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
               <elementExample id="demo">
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
                       ...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
               </elementExample>
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
tagName has the value "elementExample". Note that this is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
case-preserving in XML, as are all of the operations of the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
DOM.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
=item getAttribute (name)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
Retrieves an attribute value by name.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
Return Value: The Attr value as a string, or the empty string if that
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
attribute does not have a specified or default value.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
=item setAttribute (name, value)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
Adds a new attribute. If an attribute with that name is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
already present in the element, its value is changed to be
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
that of the value parameter. This value is a simple string,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
it is not parsed as it is being set. So any markup (such as
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
syntax to be recognized as an entity reference) is treated as
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
literal text, and needs to be appropriately escaped by the
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
implementation when it is written out. In order to assign an
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
attribute value that contains entity references, the user
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
must create an Attr node plus any Text and EntityReference
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
nodes, build the appropriate subtree, and use
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
setAttributeNode to assign it as the value of an attribute.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
DOMExceptions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
=item * INVALID_CHARACTER_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
Raised if the specified name contains an invalid character.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
=item * NO_MODIFICATION_ALLOWED_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
Raised if this node is readonly.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
=item removeAttribute (name)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
Removes an attribute by name. If the removed attribute has a
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
default value it is immediately replaced.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
DOMExceptions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
=item * NO_MODIFICATION_ALLOWED_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
Raised if this node is readonly.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
=item getAttributeNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
Retrieves an Attr node by name.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
Return Value: The Attr node with the specified attribute name or undef
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
if there is no such attribute.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
=item setAttributeNode (attr)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
Adds a new attribute. If an attribute with that name is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
already present in the element, it is replaced by the new one.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
Return Value: If the newAttr attribute replaces an existing attribute
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
with the same name, the previously existing Attr node is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
returned, otherwise undef is returned.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
DOMExceptions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
=item * WRONG_DOCUMENT_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
Raised if newAttr was created from a different document than the one that created
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
the element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
=item * NO_MODIFICATION_ALLOWED_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
Raised if this node is readonly.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
=item * INUSE_ATTRIBUTE_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
Raised if newAttr is already an attribute of another Element object. The DOM
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
user must explicitly clone Attr nodes to re-use them in other elements.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
=item removeAttributeNode (oldAttr)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
Removes the specified attribute. If the removed Attr has a default value it is
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
immediately replaced. If the Attr already is the default value, nothing happens
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
and nothing is returned.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
Parameters:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
 I<oldAttr>  The Attr node to remove from the attribute list. 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
Return Value: The Attr node that was removed.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
DOMExceptions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
=item * NO_MODIFICATION_ALLOWED_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
Raised if this node is readonly.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
=item * NOT_FOUND_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
Raised if oldAttr is not an attribute of the element.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
=head2 Additional methods not in the DOM Spec
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
=item setTagName (newTagName)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
Sets the tag name of the Element. Note that this method is not portable
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
between DOM implementations.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
DOMExceptions:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
=over 4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
=item * INVALID_CHARACTER_ERR
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
Raised if the specified name contains an invalid character.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
=back
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
=item check ($checker)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
Uses the specified L<XML::Checker> to validate the document.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
NOTE: an XML::Checker must be supplied. The checker can be created in
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
different ways, e.g. when parsing a document with XML::DOM::ValParser,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
or with XML::DOM::Document::createChecker().
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
See L<XML::Checker> for more info.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
=back