Package pyxb :: Package utils :: Module domutils
[hide private]
[frames] | no frames]

Module domutils

source code

Functions that support activities related to the Document Object Model.

Classes [hide private]
  _BDSNamespaceSupport
Class holding information relevant to generating the namespace aspects of a DOM instance.
  BindingDOMSupport
This holds DOM-related information used when generating a DOM tree from a binding instance.
Functions [hide private]
 
GetDOMImplementation()
Return the DOMImplementation object used for pyxb operations.
source code
 
SetDOMImplementation(dom_implementation)
Override the default DOMImplementation object.
source code
 
StringToDOM(text, **kw)
Convert string to a DOM instance.
source code
 
NodeAttribute(node, attribute_ncname, attribute_ns=None)
Namespace-aware search for an optional attribute in a node.
source code
xml.dom.Node
LocateUniqueChild(node, tag, absent_ok=True, namespace=pyxb.namespace.XMLSchema)
Locate a unique child of the DOM node.
source code
list(xml.dom.Node)
LocateMatchingChildren(node, tag, namespace=pyxb.namespace.XMLSchema)
Locate all children of the DOM node that have a particular tag.
source code
xml.dom.Node
LocateFirstChildElement(node, absent_ok=True, require_unique=False, ignore_annotations=True)
Locate the first element child of the node.
source code
bool
HasNonAnnotationChild(node)
Return True iff node has an ELEMENT_NODE child that is not an XMLSchema annotation node.
source code
unicode or str
ExtractTextContent(node)
Walk all the children, extracting all text content and catenating it into the return value.
source code
Variables [hide private]
  __DOMImplementation = xml.dom.getDOMImplementation()
  __package__ = 'pyxb.utils'
Function Details [hide private]

GetDOMImplementation()

source code 

Return the DOMImplementation object used for pyxb operations.

This is primarily used as the default implementation when generating DOM trees from a binding instance. It defaults to whatever xml.dom.getDOMImplementation() returns in your installation (often xml.dom.minidom). It can be overridden with SetDOMImplementation().

StringToDOM(text, **kw)

source code 

Convert string to a DOM instance.

See Also: pyxb._SetXMLStyle.

NodeAttribute(node, attribute_ncname, attribute_ns=None)

source code 

Namespace-aware search for an optional attribute in a node.

Parameters:
  • attribute_ncname (str or unicode) - The local name of the attribute.
  • attribute_ns (None or str or unicode or pyxb.namespace.Namespace) - The namespace of the attribute. Defaults to None since most attributes are not in a namespace. Can be provided as either a pyxb.namespace.Namespace instance, or a string URI.
Returns:
The value of the attribute, or None if the attribute is not present. (Unless None, the value will always be a (unicode) string.)

LocateUniqueChild(node, tag, absent_ok=True, namespace=pyxb.namespace.XMLSchema)

source code 

Locate a unique child of the DOM node.

This function returns the sole child of node which is an ELEMENT_NODE instance and has a tag consistent with the given tag. If multiple nodes with a matching tag are found, or absent_ok is False and no matching tag is found, an exception is raised.

Parameters:
  • node - An a xml.dom.Node ELEMENT_NODE instance
  • tag - the NCName of an element in the namespace
  • absent_ok - If True (default), None is returned if no match can be found. If False, an exception is raised if no match can be found.
  • namespace - The namespace to which the child element belongs. Default is the XMLSchema namespace.
Returns: xml.dom.Node
Raises:

LocateMatchingChildren(node, tag, namespace=pyxb.namespace.XMLSchema)

source code 

Locate all children of the DOM node that have a particular tag.

This function returns a list of children of node which are ELEMENT_NODE instances and have a tag consistent with the given tag.

Parameters:
  • node - An a xml.dom.Node ELEMENT_NODE instance.
  • tag - the NCName of an element in the namespace, which defaults to the XMLSchema namespace.
  • namespace - The namespace to which the child element belongs. Default is the XMLSchema namespace.
Returns: list(xml.dom.Node)

LocateFirstChildElement(node, absent_ok=True, require_unique=False, ignore_annotations=True)

source code 

Locate the first element child of the node.

Parameters:
  • node - An a xml.dom.Node ELEMENT_NODE instance.
  • absent_ok - If True (default), None is returned if no match can be found. If False, an exception is raised if no match can be found.
  • require_unique - If False (default), it is acceptable for there to be multiple child elements. If True, presence of multiple child elements raises an exception.
  • ignore_annotations - If True (default), annotations are skipped wheen looking for the first child element. If False, an annotation counts as an element.
Returns: xml.dom.Node
Raises:

ExtractTextContent(node)

source code 

Walk all the children, extracting all text content and catenating it into the return value.

Returns None if no text content (including whitespace) is found.

This is mainly used to strip comments out of the content of complex elements with simple types.

Returns: unicode or str