1XML::DOM::Element(3)  User Contributed Perl Documentation XML::DOM::Element(3)
2
3
4

NAME

6       XML::DOM::Element - An XML element node in XML::DOM
7

DESCRIPTION

9       XML::DOM::Element extends XML::DOM::Node.
10
11       By far the vast majority of objects (apart from text) that authors
12       encounter when traversing a document are Element nodes. Assume the fol‐
13       lowing XML document:
14
15            <elementExample id="demo">
16              <subelement1/>
17              <subelement2><subsubelement/></subelement2>
18            </elementExample>
19
20       When represented using DOM, the top node is an Element node for "ele‐
21       mentExample", which contains two child Element nodes, one for "subele‐
22       ment1" and one for "subelement2". "subelement1" contains no child
23       nodes.
24
25       Elements may have attributes associated with them; since the Element
26       interface inherits from Node, the generic Node interface method getAt‐
27       tributes may be used to retrieve the set of all attributes for an ele‐
28       ment. There are methods on the Element interface to retrieve either an
29       Attr object by name or an attribute value by name. In XML, where an
30       attribute value may contain entity references, an Attr object should be
31       retrieved to examine the possibly fairly complex sub-tree representing
32       the attribute value. On the other hand, in HTML, where all attributes
33       have simple string values, methods to directly access an attribute
34       value can safely be used as a convenience.
35
36       METHODS
37
38       getTagName
39           The name of the element. For example, in:
40
41                          <elementExample id="demo">
42                                  ...
43                          </elementExample>
44
45           tagName has the value "elementExample". Note that this is case-pre‐
46           serving in XML, as are all of the operations of the DOM.
47
48       getAttribute (name)
49           Retrieves an attribute value by name.
50
51           Return Value: The Attr value as a string, or the empty string if
52           that attribute does not have a specified or default value.
53
54       setAttribute (name, value)
55           Adds a new attribute. If an attribute with that name is already
56           present in the element, its value is changed to be that of the
57           value parameter. This value is a simple string, it is not parsed as
58           it is being set. So any markup (such as syntax to be recognized as
59           an entity reference) is treated as literal text, and needs to be
60           appropriately escaped by the implementation when it is written out.
61           In order to assign an attribute value that contains entity refer‐
62           ences, the user must create an Attr node plus any Text and Enti‐
63           tyReference nodes, build the appropriate subtree, and use setAt‐
64           tributeNode to assign it as the value of an attribute.
65
66           DOMExceptions:
67
68           * INVALID_CHARACTER_ERR
69               Raised if the specified name contains an invalid character.
70
71           * NO_MODIFICATION_ALLOWED_ERR
72               Raised if this node is readonly.
73
74       removeAttribute (name)
75           Removes an attribute by name. If the removed attribute has a
76           default value it is immediately replaced.
77
78           DOMExceptions:
79
80           * NO_MODIFICATION_ALLOWED_ERR
81               Raised if this node is readonly.
82
83       getAttributeNode
84           Retrieves an Attr node by name.
85
86           Return Value: The Attr node with the specified attribute name or
87           undef if there is no such attribute.
88
89       setAttributeNode (attr)
90           Adds a new attribute. If an attribute with that name is already
91           present in the element, it is replaced by the new one.
92
93           Return Value: If the newAttr attribute replaces an existing
94           attribute with the same name, the previously existing Attr node is
95           returned, otherwise undef is returned.
96
97           DOMExceptions:
98
99           * WRONG_DOCUMENT_ERR
100               Raised if newAttr was created from a different document than
101               the one that created the element.
102
103           * NO_MODIFICATION_ALLOWED_ERR
104               Raised if this node is readonly.
105
106           * INUSE_ATTRIBUTE_ERR
107               Raised if newAttr is already an attribute of another Element
108               object. The DOM user must explicitly clone Attr nodes to re-use
109               them in other elements.
110
111       removeAttributeNode (oldAttr)
112           Removes the specified attribute. If the removed Attr has a default
113           value it is immediately replaced. If the Attr already is the
114           default value, nothing happens and nothing is returned.
115
116           Parameters:
117            oldAttr  The Attr node to remove from the attribute list.
118
119           Return Value: The Attr node that was removed.
120
121           DOMExceptions:
122
123           * NO_MODIFICATION_ALLOWED_ERR
124               Raised if this node is readonly.
125
126           * NOT_FOUND_ERR
127               Raised if oldAttr is not an attribute of the element.
128
129           Additional methods not in the DOM Spec
130
131           setTagName (newTagName)
132               Sets the tag name of the Element. Note that this method is not
133               portable between DOM implementations.
134
135               DOMExceptions:
136
137               * INVALID_CHARACTER_ERR
138                   Raised if the specified name contains an invalid character.
139
140           check ($checker)
141               Uses the specified XML::Checker to validate the document.
142               NOTE: an XML::Checker must be supplied. The checker can be cre‐
143               ated in different ways, e.g. when parsing a document with
144               XML::DOM::ValParser, or with XML::DOM::Document::create‐
145               Checker().  See XML::Checker for more info.
146
147
148
149perl v5.8.8                       2002-02-08              XML::DOM::Element(3)
Impressum