Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
xml.dom.expatbuilder.Namespaces Class Reference
Inheritance diagram for xml.dom.expatbuilder.Namespaces:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def createParser
def install
def start_namespace_decl_handler
def start_element_handler
def end_element_handler

Public Attributes

 curNode

Private Member Functions

def _initNamespaces

Private Attributes

 _ns_ordered_prefixes

Detailed Description

Mix-in class for builders; adds support for namespaces.

Definition at line 718 of file expatbuilder.py.


Member Function Documentation

Definition at line 721 of file expatbuilder.py.

00721 
00722     def _initNamespaces(self):
00723         # list of (prefix, uri) ns declarations.  Namespace attrs are
00724         # constructed from this and added to the element's attrs.
00725         self._ns_ordered_prefixes = []

Here is the caller graph for this function:

Create a new namespace-handling parser.

Definition at line 726 of file expatbuilder.py.

00726 
00727     def createParser(self):
00728         """Create a new namespace-handling parser."""
00729         parser = expat.ParserCreate(namespace_separator=" ")
00730         parser.namespace_prefixes = True
00731         return parser

Definition at line 801 of file expatbuilder.py.

00801 
00802         def end_element_handler(self, name):
00803             curNode = self.curNode
00804             if ' ' in name:
00805                 uri, localname, prefix, qname = _parse_ns_name(self, name)
00806                 assert (curNode.namespaceURI == uri
00807                         and curNode.localName == localname
00808                         and curNode.prefix == prefix), \
00809                         "element stack messed up! (namespace)"
00810             else:
00811                 assert curNode.nodeName == name, \
00812                        "element stack messed up - bad nodeName"
00813                 assert curNode.namespaceURI == EMPTY_NAMESPACE, \
00814                        "element stack messed up - bad namespaceURI"
00815             self.curNode = curNode.parentNode
00816             self._finish_end_element(curNode)
00817 

Here is the call graph for this function:

def xml.dom.expatbuilder.Namespaces.install (   self,
  parser 
)
Insert the namespace-handlers onto the parser.

Definition at line 732 of file expatbuilder.py.

00732 
00733     def install(self, parser):
00734         """Insert the namespace-handlers onto the parser."""
00735         ExpatBuilder.install(self, parser)
00736         if self._options.namespace_declarations:
00737             parser.StartNamespaceDeclHandler = (
00738                 self.start_namespace_decl_handler)

Here is the call graph for this function:

def xml.dom.expatbuilder.Namespaces.start_element_handler (   self,
  name,
  attributes 
)

Definition at line 743 of file expatbuilder.py.

00743 
00744     def start_element_handler(self, name, attributes):
00745         if ' ' in name:
00746             uri, localname, prefix, qname = _parse_ns_name(self, name)
00747         else:
00748             uri = EMPTY_NAMESPACE
00749             qname = name
00750             localname = None
00751             prefix = EMPTY_PREFIX
00752         node = minidom.Element(qname, uri, prefix, localname)
00753         node.ownerDocument = self.document
00754         _append_child(self.curNode, node)
00755         self.curNode = node
00756 
00757         if self._ns_ordered_prefixes:
00758             for prefix, uri in self._ns_ordered_prefixes:
00759                 if prefix:
00760                     a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
00761                                      XMLNS_NAMESPACE, prefix, "xmlns")
00762                 else:
00763                     a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
00764                                      "xmlns", EMPTY_PREFIX)
00765                 d = a.childNodes[0].__dict__
00766                 d['data'] = d['nodeValue'] = uri
00767                 d = a.__dict__
00768                 d['value'] = d['nodeValue'] = uri
00769                 d['ownerDocument'] = self.document
00770                 _set_attribute_node(node, a)
00771             del self._ns_ordered_prefixes[:]
00772 
00773         if attributes:
00774             _attrs = node._attrs
00775             _attrsNS = node._attrsNS
00776             for i in range(0, len(attributes), 2):
00777                 aname = attributes[i]
00778                 value = attributes[i+1]
00779                 if ' ' in aname:
00780                     uri, localname, prefix, qname = _parse_ns_name(self, aname)
00781                     a = minidom.Attr(qname, uri, localname, prefix)
00782                     _attrs[qname] = a
00783                     _attrsNS[(uri, localname)] = a
00784                 else:
00785                     a = minidom.Attr(aname, EMPTY_NAMESPACE,
00786                                      aname, EMPTY_PREFIX)
00787                     _attrs[aname] = a
00788                     _attrsNS[(EMPTY_NAMESPACE, aname)] = a
00789                 d = a.childNodes[0].__dict__
00790                 d['data'] = d['nodeValue'] = value
00791                 d = a.__dict__
00792                 d['ownerDocument'] = self.document
00793                 d['value'] = d['nodeValue'] = value
00794                 d['ownerElement'] = node

Here is the call graph for this function:

Push this namespace declaration on our storage.

Definition at line 739 of file expatbuilder.py.

00739 
00740     def start_namespace_decl_handler(self, prefix, uri):
00741         """Push this namespace declaration on our storage."""
00742         self._ns_ordered_prefixes.append((prefix, uri))

Here is the caller graph for this function:


Member Data Documentation

Definition at line 724 of file expatbuilder.py.

Definition at line 754 of file expatbuilder.py.


The documentation for this class was generated from the following file: