text: xml.dom — The Document Object Model API.
  Module Contents
  The
  xml.dom contains the following functions:
  xml.dom.registerDOMImplementation(name, factory)
  The value used to indicate that no namespace is associated with a node in the DOM. This is typically found as the
  namespaceURIof a node, or used as the namespaceURI parameter to a namespaces-specific method.
  xml.dom.XML_NAMESPACE
  The namespace URI associated with the reserved prefix
  xml, as defined by Namespaces in XML (section 4).
  xml.dom.XMLNS_NAMESPACE
  The namespace URI for namespace declarations, as defined by Document Object Model (DOM) Level 2 Core Specification (section 1.1.8).
  xml.dom.XHTML_NAMESPACE.
  Objects in the DOM.
  DOMImplementation Objects)
  Return
  Trueif the feature identified by the pair of strings feature and version is implemented.
  DOMImplementation.createDocument(namespaceUri, qualifiedName, doctype).
  DOMImplementation.createDocumentType(qualifiedName, publicId, systemId)
  Return a new
  DocumentTypeobject that encapsulates the given qualifiedName, publicId, and systemId strings, representing the information contained in an XML document type declaration.
  Node Objects
  All of the components of an XML document are subclasses of
  Node.
  Node.nodeType
  An integer representing the node type. Symbolic constants for the types are on the
  Nodeobject:
  ELEMENT_NODE,
  ATTRIBUTE_NODE,
  TEXT_NODE,
  CDATA_SECTION_NODE,
  ENTITY_NODE,
  PROCESSING_INSTRUCTION_NODE,
  COMMENT_NODE,
  DOCUMENT_NODE,
  DOCUMENT_TYPE_NODE,
  NOTATION_NODE. This is a read-only attribute.
  Node.parentNode
  A
  NamedNodeMapof attribute objects. Only elements have actual values for this; others provide
  Nonefor this attribute. This is a read-only attribute.
  Node.previousSibling
  The node that immediately follows this one with the same parent. See also
  previousSibling. If this is the last child of the parent, this attribute will be
  None. This is a read-only attribute.
  Node.childNodes
  A list of nodes contained within this node. This is a read-only attribute.
  Node.firstChild
  The first child of the node, if there are any, or
  None. This is a read-only attribute.
  Node.lastChild
  The last child of the node, if there are any, or
  None. This is a read-only attribute.
  Node.localName
  The part of the
  tagNamefollowing the colon if there is one, else the entire
  tagName. The value is a string.
  Node.prefix
  The part of the
  tagNamepreceding the colon if there is one, else the empty string. The value is a string, or
  None.
  Node.namespaceURI
  The namespace associated with the element name. This will be a string or
  None. This is a read-only attribute.
  Node.nodeName
  This has a different meaning for each node type; see the DOM specification for details. The situation is similar to that with
  nodeName. The value is a string or
  None.
  Node.hasAttributes()
  Return
  Trueif the node has any attributes.
  Node.hasChildNodes()
  Return
  Trueif the node has any child nodes.
  Node.isSameNode(other)
  Return
  Trueif)
  Add a new child node to this node at the end of the list of children, returning newChild. If the node was already in the tree, it is removed first.
  Node.insertBefore(newChild, refChild))
  Remove a child node. oldChild must be a child of this node; if not,
  ValueErroris raised. oldChild is returned on success. If oldChild will not be used further, its
  unlink()method should be called.
  Node.replaceChild(newChild, oldChild)
  Replace an existing node with a new node. It must be the case that oldChild is a child of this node; if not,
  ValueErroris raised.
  Node.normalize()
  Join adjacent text nodes so that all stretches of text are stored as single
  Textinstances. This simplifies processing text from a DOM tree for many applications.
  Node.cloneNode(deep)
  Clone this node. Setting deep means to clone all child nodes as well. This returns the clone.
  NodeList Objects)
  Return the i’th item from the sequence, if there is one, or
  None. The index i is not allowed to be less than zero or greater than or equal to the length of the sequence.
  NodeList.length.
  DocumentType Objects
  The public identifier for the external subset of the document type definition. This will be a string or
  None.
  DocumentType.systemId
  The system identifier for the external subset of the document type definition. This will be a URI as a string, or
  None.
  DocumentType.internalSubset
  A string giving the complete internal subset from the document. This does not include the brackets which enclose the subset. If the document has no internal subset, this should be
  None.
  DocumentType.name
  The name of the root element as given in the
  DOCTYPEdeclaration, if present.
  DocumentType.entities.
  Document Objects
  A
  Document represents an entire XML document, including its constituent elements, attributes, processing instructions, comments etc. Remember that it inherits properties from
  Node.
  Document.documentElement
  The one and only root element of the document.
  Document.createElement(tagName)
  Create and return a new element node. The element is not inserted into the document when it is created. You need to explicitly insert it with one of the other methods such as
  insertBefore()or
  appendChild().
  Document.createElementNS(namespaceURI, tagName))
  Create and return a text node containing the data passed as a parameter. As with the other creation methods, this one does not insert the node into the tree.
  Document.createComment(data)
  Create and return a comment node containing the data passed as a parameter. As with the other creation methods, this one does not insert the node into the tree.
  Document.createProcessingInstruction(target, data)
  Create and return a processing instruction node containing the target and data passed as parameters. As with the other creation methods, this one does not insert the node into the tree.
  Document.createAttribute(name)
  Create and return an attribute node. This method does not associate the attribute node with any particular element. You must use
  setAttributeNode()on the appropriate
  Elementobject to use the newly created attribute instance.
  Document.createAttributeNS(namespaceURI, qualifiedName))
  Search for all descendants (direct children, children’s children, etc.) with a particular element type name.
  Document.getElementsByTagNameNS(namespaceURI, localName)
  Search for all descendants (direct children, children’s children, etc.) with a particular namespace URI and localname. The localname is the part of the namespace after the prefix.
  Element Objects
  Element is a subclass of
  Node, so inherits all the attributes of that class.
  Element.tagName
  The element type name. In a namespace-using document it may have colons in it. The value is a string.
  Element.getElementsByTagName(tagName)
  Same as equivalent method in the
  Documentclass.
  Element.getElementsByTagNameNS(namespaceURI, localName)
  Same as equivalent method in the
  Documentclass.
  Element.hasAttribute(name)
  Return
  Trueif the element has an attribute named by name.
  Element.hasAttributeNS(namespaceURI, localName)
  Return
  Trueif the element has an attribute named by namespaceURI and localName.
  Element.getAttribute(name)
  Return the value of the attribute named by name as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value.
  Element.getAttributeNode(attrname)
  Return the
  Attrnode for the attribute named by attrname.
  Element.getAttributeNS(namespaceURI, localName)
  Return the value of the attribute named by namespaceURI and localName as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value.
  Element.getAttributeNodeNS(namespaceURI, localName)
  Return an attribute value as a node, given a namespaceURI and localName.
  Element.removeAttribute(name)
  Remove an attribute by name. If there is no matching attribute, a
  NotFoundErris raised.
  Element.removeAttributeNode(oldAttr)
  Remove and return oldAttr from the attribute list, if present. If oldAttr is not present,
  NotFoundErris raised.
  Element.removeAttributeNS(namespaceURI, localName)
  Remove an attribute by name. Note that it uses a localName, not a qname. No exception is raised if there is no matching attribute.
  Element.setAttribute(name, value)
  Set an attribute value from a string.
  Element.setAttributeNode(newAttr))
  Add a new attribute node to the element, replacing an existing attribute if necessary if the
  namespaceURIand
  localNameattributes match. If a replacement occurs, the old attribute node will be returned. If newAttr is already in use,
  InuseAttributeErrwill be raised.
  Element.setAttributeNS(namespaceURI, qname, value)
  Set an attribute value from a string, given a namespaceURI and a qname. Note that a qname is the whole attribute name. This is different than above.
  Attr Objects
  Attr inherits from
  Node, so inherits all its attributes.
  Attr.name
  The attribute name. In a namespace-using document it may include a colon.
  Attr.localName
  The part of the name following the colon if there is one, else the entire name. This is a read-only attribute.
  Attr.prefix
  The part of the name preceding the colon if there is one, else the empty string.
  Attr.value
  The text value of the attribute. This is a synonym for the
  nodeValueattribute.
  NamedNodeMap Objects
  NamedNodeMap does not inherit from
  Node.
  NamedNodeMap.length
  The length of the attribute list.
  NamedNodeMap.item(index).
  Comment Objects
  Comment represents a comment in the XML document. It is a subclass of
  Node, but cannot have child nodes.
  Comment.data
  The content of the comment as a string. The attribute contains all characters between the leading
  <!-
  -and trailing
  -
  ->, but does not include them.
  Text and CDATASection.
  Text.data.
  ProcessingInstruction Objects
  Represents a processing instruction in the XML document; this inherits from the
  Node interface and cannot have child nodes.
  ProcessingInstruction.target
  The content of the processing instruction up to the first whitespace character. This is a read-only attribute.
  ProcessingInstruction.data
  The content of the processing instruction following the first whitespace character.
  Exceptions
  Base exception class used for all specific DOM exceptions. This exception class cannot be directly instantiated.
  exception xml.dom.DomstringSizeErr
  Raised when a specified range of text does not fit into a string. This is not known to be used in the Python DOM implementations, but may be received from DOM implementations not written in Python.
  exception xml.dom.HierarchyRequestErr
  Raised when an attempt is made to insert a node where the node type is not allowed.
  exception xml.dom.IndexSizeErr
  Raised when an index or size parameter to a method is negative or exceeds the allowed values.
  exception xml.dom.InuseAttributeErr
  Raised when an attempt is made to insert an
  Attrnode that is already present elsewhere in the document.
  exception xml.dom.InvalidAccessErr
  Raised if a parameter or an operation is not supported on the underlying object.
  exception xml.dom.InvalidCharacterErr
  Raised when an attempt is made to modify the type of a node.
  exception xml.dom.InvalidStateErr
  Raised when an attempt is made to use an object that is not defined or is no longer usable.
  exception xml.dom.NamespaceErr
  If an attempt is made to change any object in a way that is not permitted with regard to the Namespaces in XML recommendation, this exception is raised.
  exception xml.dom.NotFoundErr
  Exception when a node does not exist in the referenced context. For example,
  NamedNodeMap.removeNamedItem()will raise this if the node passed in does not exist in the map.
  exception xml.dom.NotSupportedErr
  Raised when the implementation does not support the requested type of object or operation.
  exception xml.dom.NoDataAllowedErr
  This is raised if data is specified for a node which does not support data.
  exception xml.dom.NoModificationAllowedErr
  Raised on attempts to modify an object where modifications are not allowed (such as for read-only nodes).
  exception xml.dom.SyntaxErr
  Raised when an invalid or illegal string is specified.
  exception xml.dom.WrongDocumentErr.
  License
  © 2001–2021 Python Software Foundation
  Licensed under the PSF License.