⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07_02.htm

📁 Perl & XML. by Erik T. Ray and Jason McIntosh ISBN 0-596-00205-X First Edition, published April
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html><head><title>DOM Class Interface Reference (Perl and XML)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Erik T. Ray and Jason McIntosh" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="059600205XL" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl and XML" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl &amp; XML" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch07_01.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch07_03.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">7.2. DOM Class Interface Reference</h2><p>Since <a name="INDEX-527" />DOM<a name="INDEX-528" />is becoming the interface of choice in the Perl-XML world, itdeserves more elaboration. The following sections describe classinterfaces individually, listing their properties, methods, andintended purposes.</p><a name="ch07-4-fm2xml" /><blockquote><b>WARNING:</b> The DOM specification calls for <a name="INDEX-529" />UTF-16 as the standard encoding.However, most Perl implementations assume a UTF-8 encoding. Due tolimitations in Perl, working with characters of lengths other than 8bits is difficult. This will change in a future version, andencodings like UTF-16 will be supported more readily.</p></blockquote><a name="perlxml-CHP-7-SECT-2.1" /><div class="sect2"><h3 class="sect2">7.2.1. Document</h3><p>The <a name="INDEX-530" /><tt class="literal">Document</tt> class controlsthe overall document, creating new objects when requested andmaintaining high-level information such as references to the documenttype declaration and the root element.</p><a name="perlxml-CHP-7-SECT-2.1.1" /><div class="sect3"><h3 class="sect3">7.2.1.1. Properties</h3><dl><a name="INDEX-531" /><a name="INDEX-532" /><a name="INDEX-533" /><dt><b>doctype</b></dt><dd><p>Document Type Declaration (DTD).</p></dd><a name="INDEX-534" /><dt><i>documentElement</i></dt><dd><p>The root element of the document. </p></dd></dl></div><a name="perlxml-CHP-7-SECT-2.1.2" /><div class="sect3"><h3 class="sect3">7.2.1.2. Methods</h3><dl><a name="INDEX-535" /><a name="INDEX-536" /><a name="INDEX-537" /><a name="INDEX-538" /><a name="INDEX-539" /><a name="INDEX-540" /><a name="INDEX-541" /><a name="INDEX-542" /><dt><i>createElement, createTextNode, createComment, createCDATASection, createProcessingInstruction, createAttribute, createEntityReference</i></dt><dd><p>Generates a new node object. </p></dd><a name="INDEX-543" /><a name="INDEX-544" /><dt><i>createElementNS, createAttributeNS (DOM2 only)</i></dt><dd><p>Generates a new element or attribute node object with a specifiednamespace qualifier.</p></dd><a name="INDEX-545" /><dt><i>createDocumentFragment</i></dt><dd><p>Creates a container object for a document's subtree. </p></dd><a name="INDEX-546" /><dt><i>getElementsByTagName</i></dt><dd><p>Returns a NodeList of all elements having a given tag name at anylevel of the document.</p></dd><a name="INDEX-547" /><dt><i>getElementsByTagNameNS (DOM2 only)</i></dt><dd><p>Returns a NodeList of all elements having a given namespace qualifierand local name. The asterisk character (*) matches any element or anynamespace, allowing you to find all elements in a given namespace.</p></dd><a name="INDEX-548" /><dt><i>getElementById (DOM2 only)</i></dt><dd><p>Returns a reference to the node that has a specified ID attribute. </p></dd><a name="INDEX-549" /><dt><i>importNode (DOM2 only)</i></dt><dd><p>Creates a new node that is the copy of a node from another document.Acts like a "copy to the clipboard"operation for importing markup.</p></dd></dl></div></div><a name="perlxml-CHP-7-SECT-2.2" /><div class="sect2"><h3 class="sect2">7.2.2. DocumentFragment</h3><p>The<a name="INDEX-550" /> <tt class="literal">DocumentFragment</tt> classis used to contain a document fragment. Its children are (zero ormore) nodes representing the tops of XML trees. This class contrastswith <tt class="literal">Document</tt>, which has at most one childelement, the document root, plus metadata like the document type. Inthis respect, <tt class="literal">DocumentFragment</tt>'scontent is not well-formed, though it must obey the XML well-formedrules in all other respects (no illegal characters in text, etc.)</p><p>No specific methods or properties are defined; use the generic nodemethods to access data.</p></div><a name="perlxml-CHP-7-SECT-2.3" /><div class="sect2"><h3 class="sect2">7.2.3. DocumentType</h3><p>This <a name="INDEX-551" />class contains all the information containedin the document type declaration at the beginning of the document,except the specifics about an external DTD. Thus, it names the rootelement and any declared entities or notations in the internalsubset.</p><p>No specific methods are defined for this class, but the propertiesare public (but read-only).</p><a name="perlxml-CHP-7-SECT-2.3.1" /><div class="sect3"><h3 class="sect3">7.2.3.1. Properties</h3><dl><a name="INDEX-552" /><a name="INDEX-553" /><dt><i>name</i></dt><dd><p>The name of the root element.</p></dd><a name="INDEX-554" /><dt><i>entities</i></dt><dd><p>A <tt class="literal">NamedNodeMap</tt> of entity declarations. </p></dd><a name="INDEX-555" /><dt><i>notation</i></dt><dd><p>A <tt class="literal">NamedNodeMap</tt> of notation declarations. </p></dd><a name="INDEX-556" /><dt><i>internalSubset (DOM2 only)</i></dt><dd><p>The internal subset of the DTD represented as a string. </p></dd><a name="INDEX-557" /><dt><i>publicId (DOM2 only)</i></dt><dd><p>The external subset of the DTD's public identifier. </p></dd><a name="INDEX-558" /><dt><i>systemId (DOM2 only)</i></dt><dd><p>The external subset of the DTD's system identifier. </p></dd></dl></div></div><a name="perlxml-CHP-7-SECT-2.4" /><div class="sect2"><h3 class="sect2">7.2.4. Node</h3><p>All node types inherit from the class<tt class="literal">Node</tt><a name="INDEX-559" />. Any properties or methods common to allnode types can be accessed through this class. A few properties, suchas the <tt class="literal">value</tt> of the node, are undefined for somenode types, like <tt class="literal">Element</tt>. The generic methods ofthis class are useful in some programming contexts, such as whenwriting code that processes nodes of different types. At other times,you'll know in advance what typeyou're working with, and you should use the specificclass's methods instead.</p><p>All properties but <tt class="literal">nodeValue</tt> and<tt class="literal">prefix</tt> are read-only.</p><a name="perlxml-CHP-7-SECT-2.4.1" /><div class="sect3"><h3 class="sect3">7.2.4.1. Properties</h3><dl><a name="INDEX-560" /><a name="INDEX-561" /><dt><i>nodeName</i></dt><dd><p>A property that is defined for elements, attributes, and entities. Inthe context of elements this property would be thetag's name.</p></dd><a name="INDEX-562" /><dt><i>nodeValue</i></dt><dd><p>A property defined for attributes, text nodes, CDATA nodes, PIs, andcomments.</p></dd><a name="INDEX-563" /><dt><i>nodeType</i></dt><dd><p>One of the following types of nodes: <tt class="literal">Element</tt>,<tt class="literal">Attr</tt>, <tt class="literal">Text</tt>,<tt class="literal">CDATASection</tt>, <tt class="literal">EntityReference</tt>,<tt class="literal">Entity</tt>, <tt class="literal">ProcessingInstruction</tt>,<tt class="literal">Comment</tt>, <tt class="literal">Document</tt>,<tt class="literal">DocumentType</tt>, <tt class="literal">DocumentFragment</tt>,or <tt class="literal">Notation</tt>.</p></dd><a name="INDEX-564" /><dt><i>parentNode</i></dt><dd><p>A reference to the parent of this node. </p></dd><a name="INDEX-565" /><dt><i>childNodes</i></dt><dd><p>An ordered list of references to children of this node (if any). </p></dd><a name="INDEX-566" /><a name="INDEX-567" /><dt><i>firstChild, lastChild</i></dt><dd><p>References to the first and last of the node'schildren (if any).</p></dd><a name="INDEX-568" /><a name="INDEX-569" /><dt><i>previousSibling, nextSibling</i></dt><dd><p>The node immediately preceding or following this one, respectively. </p></dd><a name="INDEX-570" /><dt><i>attributes</i></dt><dd><p>An unordered list (<tt class="literal">NamedNodeMap</tt>) of nodes that areattributes of this one (if any).</p></dd><a name="INDEX-571" /><dt><i>ownerDocument</i></dt><dd><p>A reference to the object containing the whole document -- usefulwhen you need to generate a new node.</p></dd><a name="INDEX-572" /><dt><i>namespaceURI (DOM2 only)</i></dt><dd><p>A namespace URI if this node has a namespace prefix; otherwise it is<tt class="literal">null</tt>.</p></dd><a name="INDEX-573" /><dt><i>prefix (DOM2 only)</i></dt><dd><p>The namespace prefix associated with this node. </p></dd></dl></div><a name="perlxml-CHP-7-SECT-2.4.2" /><div class="sect3"><h3 class="sect3">7.2.4.2. Methods</h3><dl><a name="INDEX-574" /><a name="INDEX-575" /><dt><i>insertBefore</i></dt><dd><p>Inserts a node before a reference child element. </p></dd><a name="INDEX-576" /><dt><i>replaceChild</i></dt><dd><p>Swaps a child node with a new one you supply, giving you the old onein return.</p></dd><a name="INDEX-577" /><dt><i>appendChild</i></dt><dd><p>Adds a new node to the end of this node's list ofchildren.</p></dd><a name="INDEX-578" /><dt><i>hasChildNodes</i></dt><dd><p>True if there are children of this node; otherwise, it is false. </p></dd><a name="INDEX-579" /><dt><i>cloneNode</i></dt><dd><p>Returns a duplicate copy of this node. It provides an alternate wayto generate nodes. All properties will be identical except for<tt class="literal">parentNode</tt>, which will be undefined, and<tt class="literal">childNodes</tt>, which will be empty. Cloned elementswill all have the same attributes as the original. If the argument<tt class="literal">deep</tt> is set to true, then the node and all itsdescendants will be copied.</p></dd><a name="INDEX-580" /><dt><i>hasAttributes (DOM2 only)</i></dt><dd><p>Returns true if this node has defined attributes. </p></dd><a name="INDEX-581" /><dt><i>isSupported (DOM2 only)</i></dt><dd><p>Returns true if this implementation supports a specific feature. </p></dd></dl></div></div><a name="perlxml-CHP-7-SECT-2.5" /><div class="sect2"><h3 class="sect2">7.2.5. NodeList</h3><p>This <a name="INDEX-582" />class is a container for an ordered listof nodes. It is "live," meaningthat any changes to the nodes it references will appear in thedocument immediately.</p><a name="perlxml-CHP-7-SECT-2.5.1" /><div class="sect3"><h3 class="sect3">7.2.5.1. Properties</h3><dl><a name="INDEX-583" /><a name="INDEX-584" /><dt><i>length</i></dt><dd><p>Returns an integer indicating the number of nodes in the list. </p></dd></dl></div><a name="perlxml-CHP-7-SECT-2.5.2" /><div class="sect3"><h3 class="sect3">7.2.5.2. Methods</h3><dl><a name="INDEX-585" /><a name="INDEX-586" /><dt><i>item</i></dt><dd><p>Given an integer value <em class="replaceable">n</em>, returns areference to the <em class="replaceable">n</em>th node in the list,starting at zero.</p></dd></dl></div></div><a name="perlxml-CHP-7-SECT-2.6" /><div class="sect2"><h3 class="sect2">7.2.6. NamedNodeMap</h3><p>This<a name="INDEX-587" /> unordered set of nodes is designed toallow access to nodes by name. An alternate access by index is alsoprovided for enumerations, but no order is implied.</p><a name="perlxml-CHP-7-SECT-2.6.1" /><div class="sect3"><h3 class="sect3">7.2.6.1. Properties</h3><dl><a name="INDEX-588" /><a name="INDEX-589" /><dt><i>length</i></dt><dd><p>Returns an integer indicating the number of nodes in the list. </p></dd></dl></div><a name="perlxml-CHP-7-SECT-2.6.2" /><div class="sect3"><h3 class="sect3">7.2.6.2. Methods</h3><dl><a name="INDEX-590" /><a name="INDEX-591" /><a name="INDEX-592" /><dt><i>getNamedItem, setNamedItem</i></dt><dd><p>Retrieves or adds a node using the node's<tt class="literal">nodeName</tt> property as the key.</p></dd>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -