Back to index

python3.2  3.2.2
Classes | Functions | Variables
xml.dom.minidom Namespace Reference

Classes

class  Node
class  DocumentFragment
class  Attr
class  NamedNodeMap
class  TypeInfo
class  Element
class  Childless
class  ProcessingInstruction
class  CharacterData
class  Text
class  Comment
class  CDATASection
class  ReadOnlySequentialNamedNodeMap
class  Identified
class  DocumentType
class  Entity
class  Notation
class  DOMImplementation
class  ElementInfo
class  Document

Functions

def _append_child
def _in_document
def _write_data
def _get_elements_by_tagName_helper
def _get_elements_by_tagName_ns_helper
def _set_attribute_node
def _get_containing_element
def _get_containing_entref
def _clear_id_cache
def _clone_node
def _nssplit
def _do_pulldom_parse
def parse
def parseString
def getDOMImplementation

Variables

tuple _nodeTypes_with_children
 AttributeList = NamedNodeMap
tuple _no_type = TypeInfo(None, None)

Detailed Description

\
minidom.py -- a lightweight DOM implementation.

parse("foo.xml")

parseString("<foo><bar/></foo>")

Todo:
=====
 * convenience methods for getting elements and text.
 * more testing
 * bring some of the writer and linearizer code into conformance with this
        interface
 * SAX 2 namespaces

Function Documentation

def xml.dom.minidom._append_child (   self,
  node 
) [private]

Definition at line 284 of file minidom.py.

00284 
00285 def _append_child(self, node):
00286     # fast path with less checks; usable by DOM builders if careful
00287     childNodes = self.childNodes
00288     if childNodes:
00289         last = childNodes[-1]
00290         node.__dict__["previousSibling"] = last
00291         last.__dict__["nextSibling"] = node
00292     childNodes.append(node)
00293     node.__dict__["parentNode"] = self

Here is the caller graph for this function:

def xml.dom.minidom._clear_id_cache (   node) [private]

Definition at line 1492 of file minidom.py.

01492 
01493 def _clear_id_cache(node):
01494     if node.nodeType == Node.DOCUMENT_NODE:
01495         node._id_cache.clear()
01496         node._id_search_stack = None
01497     elif _in_document(node):
01498         node.ownerDocument._id_cache.clear()
01499         node.ownerDocument._id_search_stack= None

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.minidom._clone_node (   node,
  deep,
  newOwnerDocument 
) [private]
Clone a node and give it the new owner document.
Called by Node.cloneNode and Document.importNode

Definition at line 1838 of file minidom.py.

01838 
01839 def _clone_node(node, deep, newOwnerDocument):
01840     """
01841     Clone a node and give it the new owner document.
01842     Called by Node.cloneNode and Document.importNode
01843     """
01844     if node.ownerDocument.isSameNode(newOwnerDocument):
01845         operation = xml.dom.UserDataHandler.NODE_CLONED
01846     else:
01847         operation = xml.dom.UserDataHandler.NODE_IMPORTED
01848     if node.nodeType == Node.ELEMENT_NODE:
01849         clone = newOwnerDocument.createElementNS(node.namespaceURI,
01850                                                  node.nodeName)
01851         for attr in node.attributes.values():
01852             clone.setAttributeNS(attr.namespaceURI, attr.nodeName, attr.value)
01853             a = clone.getAttributeNodeNS(attr.namespaceURI, attr.localName)
01854             a.specified = attr.specified
01855 
01856         if deep:
01857             for child in node.childNodes:
01858                 c = _clone_node(child, deep, newOwnerDocument)
01859                 clone.appendChild(c)
01860 
01861     elif node.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
01862         clone = newOwnerDocument.createDocumentFragment()
01863         if deep:
01864             for child in node.childNodes:
01865                 c = _clone_node(child, deep, newOwnerDocument)
01866                 clone.appendChild(c)
01867 
01868     elif node.nodeType == Node.TEXT_NODE:
01869         clone = newOwnerDocument.createTextNode(node.data)
01870     elif node.nodeType == Node.CDATA_SECTION_NODE:
01871         clone = newOwnerDocument.createCDATASection(node.data)
01872     elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE:
01873         clone = newOwnerDocument.createProcessingInstruction(node.target,
01874                                                              node.data)
01875     elif node.nodeType == Node.COMMENT_NODE:
01876         clone = newOwnerDocument.createComment(node.data)
01877     elif node.nodeType == Node.ATTRIBUTE_NODE:
01878         clone = newOwnerDocument.createAttributeNS(node.namespaceURI,
01879                                                    node.nodeName)
01880         clone.specified = True
01881         clone.value = node.value
01882     elif node.nodeType == Node.DOCUMENT_TYPE_NODE:
01883         assert node.ownerDocument is not newOwnerDocument
01884         operation = xml.dom.UserDataHandler.NODE_IMPORTED
01885         clone = newOwnerDocument.implementation.createDocumentType(
01886             node.name, node.publicId, node.systemId)
01887         clone.ownerDocument = newOwnerDocument
01888         if deep:
01889             clone.entities._seq = []
01890             clone.notations._seq = []
01891             for n in node.notations._seq:
01892                 notation = Notation(n.nodeName, n.publicId, n.systemId)
01893                 notation.ownerDocument = newOwnerDocument
01894                 clone.notations._seq.append(notation)
01895                 if hasattr(n, '_call_user_data_handler'):
01896                     n._call_user_data_handler(operation, n, notation)
01897             for e in node.entities._seq:
01898                 entity = Entity(e.nodeName, e.publicId, e.systemId,
01899                                 e.notationName)
01900                 entity.actualEncoding = e.actualEncoding
01901                 entity.encoding = e.encoding
01902                 entity.version = e.version
01903                 entity.ownerDocument = newOwnerDocument
01904                 clone.entities._seq.append(entity)
01905                 if hasattr(e, '_call_user_data_handler'):
01906                     e._call_user_data_handler(operation, n, entity)
01907     else:
01908         # Note the cloning of Document and DocumentType nodes is
01909         # implementation specific.  minidom handles those cases
01910         # directly in the cloneNode() methods.
01911         raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node))
01912 
01913     # Check for _call_user_data_handler() since this could conceivably
01914     # used with other DOM implementations (one of the FourThought
01915     # DOMs, perhaps?).
01916     if hasattr(node, '_call_user_data_handler'):
01917         node._call_user_data_handler(operation, node, clone)
01918     return clone
01919 

Here is the caller graph for this function:

def xml.dom.minidom._do_pulldom_parse (   func,
  args,
  kwargs 
) [private]

Definition at line 1928 of file minidom.py.

01928 
01929 def _do_pulldom_parse(func, args, kwargs):
01930     events = func(*args, **kwargs)
01931     toktype, rootNode = events.getEvent()
01932     events.expandNode(rootNode)
01933     events.clear()
01934     return rootNode

Here is the caller graph for this function:

def xml.dom.minidom._get_containing_element (   node) [private]

Definition at line 1135 of file minidom.py.

01135 
01136 def _get_containing_element(node):
01137     c = node.parentNode
01138     while c is not None:
01139         if c.nodeType == Node.ELEMENT_NODE:
01140             return c
01141         c = c.parentNode
01142     return None

Here is the caller graph for this function:

def xml.dom.minidom._get_containing_entref (   node) [private]

Definition at line 1143 of file minidom.py.

01143 
01144 def _get_containing_entref(node):
01145     c = node.parentNode
01146     while c is not None:
01147         if c.nodeType == Node.ENTITY_REFERENCE_NODE:
01148             return c
01149         c = c.parentNode
01150     return None
01151 

Here is the caller graph for this function:

def xml.dom.minidom._get_elements_by_tagName_helper (   parent,
  name,
  rc 
) [private]

Definition at line 309 of file minidom.py.

00309 
00310 def _get_elements_by_tagName_helper(parent, name, rc):
00311     for node in parent.childNodes:
00312         if node.nodeType == Node.ELEMENT_NODE and \
00313             (name == "*" or node.tagName == name):
00314             rc.append(node)
00315         _get_elements_by_tagName_helper(node, name, rc)
00316     return rc

Here is the caller graph for this function:

def xml.dom.minidom._get_elements_by_tagName_ns_helper (   parent,
  nsURI,
  localName,
  rc 
) [private]

Definition at line 317 of file minidom.py.

00317 
00318 def _get_elements_by_tagName_ns_helper(parent, nsURI, localName, rc):
00319     for node in parent.childNodes:
00320         if node.nodeType == Node.ELEMENT_NODE:
00321             if ((localName == "*" or node.localName == localName) and
00322                 (nsURI == "*" or node.namespaceURI == nsURI)):
00323                 rc.append(node)
00324             _get_elements_by_tagName_ns_helper(node, nsURI, localName, rc)
00325     return rc

Here is the caller graph for this function:

def xml.dom.minidom._in_document (   node) [private]

Definition at line 294 of file minidom.py.

00294 
00295 def _in_document(node):
00296     # return True iff node is part of a document tree
00297     while node is not None:
00298         if node.nodeType == Node.DOCUMENT_NODE:
00299             return True
00300         node = node.parentNode
00301     return False

Here is the caller graph for this function:

def xml.dom.minidom._nssplit (   qualifiedName) [private]

Definition at line 1920 of file minidom.py.

01920 
01921 def _nssplit(qualifiedName):
01922     fields = qualifiedName.split(':', 1)
01923     if len(fields) == 2:
01924         return fields
01925     else:
01926         return (None, fields[0])
01927 

Here is the caller graph for this function:

def xml.dom.minidom._set_attribute_node (   element,
  attr 
) [private]

Definition at line 882 of file minidom.py.

00882 
00883 def _set_attribute_node(element, attr):
00884     _clear_id_cache(element)
00885     element._attrs[attr.name] = attr
00886     element._attrsNS[(attr.namespaceURI, attr.localName)] = attr
00887 
00888     # This creates a circular reference, but Element.unlink()
00889     # breaks the cycle since the references to the attribute
00890     # dictionaries are tossed.
00891     attr.__dict__['ownerElement'] = element
00892 

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.minidom._write_data (   writer,
  data 
) [private]

Definition at line 302 of file minidom.py.

00302 
00303 def _write_data(writer, data):
00304     "Writes datachars to writer."
00305     if data:
00306         data = data.replace("&", "&amp;").replace("<", "&lt;"). \
00307                     replace("\"", "&quot;").replace(">", "&gt;")
00308         writer.write(data)

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.minidom.getDOMImplementation (   features = None)

Definition at line 1955 of file minidom.py.

01955 
01956 def getDOMImplementation(features=None):
01957     if features:
01958         if isinstance(features, str):
01959             features = domreg._parse_feature_string(features)
01960         for f, v in features:
01961             if not Document.implementation.hasFeature(f, v):
01962                 return None
01963     return Document.implementation

Here is the caller graph for this function:

def xml.dom.minidom.parse (   file,
  parser = None,
  bufsize = None 
)
Parse a file into a DOM by filename or file object.

Definition at line 1935 of file minidom.py.

01935 
01936 def parse(file, parser=None, bufsize=None):
01937     """Parse a file into a DOM by filename or file object."""
01938     if parser is None and not bufsize:
01939         from xml.dom import expatbuilder
01940         return expatbuilder.parse(file)
01941     else:
01942         from xml.dom import pulldom
01943         return _do_pulldom_parse(pulldom.parse, (file,),
01944             {'parser': parser, 'bufsize': bufsize})

Here is the call graph for this function:

def xml.dom.minidom.parseString (   string,
  parser = None 
)
Parse a file into a DOM from a string.

Definition at line 1945 of file minidom.py.

01945 
01946 def parseString(string, parser=None):
01947     """Parse a file into a DOM from a string."""
01948     if parser is None:
01949         from xml.dom import expatbuilder
01950         return expatbuilder.parseString(string)
01951     else:
01952         from xml.dom import pulldom
01953         return _do_pulldom_parse(pulldom.parseString, (string,),
01954                                  {'parser': parser})

Here is the call graph for this function:


Variable Documentation

tuple xml.dom.minidom._no_type = TypeInfo(None, None)

Definition at line 659 of file minidom.py.

Initial value:
00001 (xml.dom.Node.ELEMENT_NODE,
00002                             xml.dom.Node.ENTITY_REFERENCE_NODE)

Definition at line 30 of file minidom.py.

Definition at line 637 of file minidom.py.