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

Class BindingDOMSupport

source code

object --+
         |
        BindingDOMSupport

This holds DOM-related information used when generating a DOM tree from a binding instance.

Instance Methods [hide private]
 
implementation(self)
The DOMImplementation object to be used.
source code
 
document(self)
Return the document generated using this instance.
source code
 
requireXSIType(self)
Indicates whether {xsi:type<http://www.w3.org/TR/xmlschema-1/#xsi_type>} should be added to all elements.
source code
 
reset(self)
Reset this instance to the state it was when created.
source code
 
__init__(self, implementation=None, default_namespace=None, require_xsi_type=False, namespace_prefix_map=None)
Create a new instance used for building a single document.
source code
 
defaultNamespace(self)
The default namespace for this instance
source code
 
setDefaultNamespace(self, default_namespace) source code
 
declareNamespace(self, namespace, prefix=None)
Declare a namespace within this instance only.
source code
 
namespacePrefix(self, namespace, enable_default_namespace=True)
Return the prefix to be used for the given namespace.
source code
 
qnameAsText(self, qname, enable_default_namespace=True) source code
 
valueAsText(self, value, enable_default_namespace=True)
Represent a simple type value as XML text.
source code
 
addAttribute(self, element, expanded_name, value)
Add an attribute to the given element.
source code
 
addXMLNSDeclaration(self, element, namespace, prefix=None)
Manually add an XMLNS declaration to the document element.
source code
xml.dom.Document
finalize(self)
Do the final cleanup after generating the tree.
source code
xml.dom.Element
createChildElement(self, expanded_name, parent=None)
Create a new element node in the tree.
source code
( str, str )
_makeURINodeNamePair(self, node)
Convert namespace information from a DOM node to text for new DOM node.
source code
 
_deepClone(self, node, docnode) source code
 
cloneIntoImplementation(self, node)
Create a deep copy of the node in the target implementation.
source code
xml.dom.Node
appendChild(self, child, parent)
Add the child to the parent.
source code
 
appendTextChild(self, text, parent)
Add the text to the parent as a text node.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
Reset(cls)
Reset the global defaults for default/prefix/namespace information.
source code
 
DefaultNamespace(cls)
The global default namespace (used on instance creation if not overridden)
source code
 
SetDefaultNamespace(cls, default_namespace) source code
 
DeclareNamespace(cls, namespace, prefix=None)
Declare a namespace that will made available to each created instance.
source code
Class Variables [hide private]
  __implementation = None
hash(x)
  __document = None
hash(x)
  __requireXSIType = None
hash(x)
  __NamespaceContext = <pyxb.namespace.resolution.NamespaceConte...
  __namespaceContext = None
hash(x)
  __referencedNamespacePrefixes = None
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

implementation(self)

source code 

The DOMImplementation object to be used.

Defaults to pyxb.utils.domutils.GetDOMImplementation(), but can be overridden in the constructor call using the implementation keyword.

requireXSIType(self)

source code 

Indicates whether {xsi:type<http://www.w3.org/TR/xmlschema-1/#xsi_type>} should be added to all elements.

Certain WSDL styles and encodings seem to require explicit notation of the type of each element, even if it was specified in the schema.

This value can only be set in the constructor.

reset(self)

source code 

Reset this instance to the state it was when created.

This creates a new root document with no content, resets the namespace-prefix map to its as-constructed content, and clears the set of referenced namespace prefixes. The defaultNamespace and requireXSIType are not modified.

__init__(self, implementation=None, default_namespace=None, require_xsi_type=False, namespace_prefix_map=None)
(Constructor)

source code 

Create a new instance used for building a single document.

Parameters:
  • implementation - The xml.dom implementation to use. Defaults to the one selected by GetDOMImplementation.
  • default_namespace (pyxb.namespace.Namespace) - The namespace to configure as the default for the document. If not provided, there is no default namespace.
  • require_xsi_type (bool) - If True, an xsi:type attribute should be placed in every element.
  • namespace_prefix_map (map from pyxb.namespace.Namespace to str) - A map from pyxb.namespace.Namespace instances to the preferred prefix to use for the namespace in xmlns declarations. The default one assigns 'xsi' for the XMLSchema instance namespace.
Raises:
  • pyxb.LogicError - the same prefix is associated with multiple namespaces in the namespace_prefix_map.
Overrides: object.__init__

namespacePrefix(self, namespace, enable_default_namespace=True)

source code 

Return the prefix to be used for the given namespace.

This will declare the namespace if it has not yet been observed. It will also ensure the mapping from the returned prefix to namespace is recorded for addition as an xmlns directive in the final document.

Parameters:
  • namespace - The namespace for which a prefix is needed. If the provided namespace is None or an absent namespace, the None value will be returned as the corresponding prefix.
  • enable_default_namespace - Normally if the namespace is the default namespace None is returned to indicate this. If this keyword is False then we need a namespace prefix even if this is the default.

valueAsText(self, value, enable_default_namespace=True)

source code 

Represent a simple type value as XML text.

This is essentially what value.xsdLiteral() does, but this one handles any special cases such as QName values where the lexical representation cannot be done in isolation of external information such as namespace declarations.

addAttribute(self, element, expanded_name, value)

source code 

Add an attribute to the given element.

Parameters:
  • element (xml.dom.Element) - The element to which the attribute should be added
  • expanded_name (pyxb.namespace.Namespace or str or unicode) - The name of the attribute. This may be a local name if the attribute is not in a namespace.
  • value (str or unicode) - The value of the attribute

addXMLNSDeclaration(self, element, namespace, prefix=None)

source code 

Manually add an XMLNS declaration to the document element.

Parameters:
  • namespace - a pyxb.namespace.Namespace instance
  • prefix - the prefix by which the namespace is known. If None, the default prefix as previously declared will be used; if '' (empty string) a declaration for namespace as the default namespace will be generated.
Returns:
prefix as used in the added declaration.

finalize(self)

source code 

Do the final cleanup after generating the tree. This makes sure that the document element includes XML Namespace declarations for all namespaces referenced in the tree.

Returns: xml.dom.Document
The document that has been created.

createChildElement(self, expanded_name, parent=None)

source code 

Create a new element node in the tree.

Parameters:
  • expanded_name (pyxb.namespace.ExpandedName or str or unicode) - The name of the element. A plain string indicates a name in no namespace.
  • parent - The node in the tree that will serve as the child's parent. If None, the document element is used. (If there is no document element, then this call creates it as a side-effect.)
Returns: xml.dom.Element
A newly created DOM element

_makeURINodeNamePair(self, node)

source code 

Convert namespace information from a DOM node to text for new DOM node.

The namespaceURI and nodeName are extracted and parsed. The namespace (if any) is registered within the document, along with any prefix from the node name. A pair is returned where the first element is the namespace URI or None, and the second is a QName to be used for the expanded name within this document.

Parameters:
  • node - An xml.dom.Node instance, presumably from a wildcard match.
Returns: ( str, str )

cloneIntoImplementation(self, node)

source code 

Create a deep copy of the node in the target implementation.

Used when converting a DOM instance from one implementation (e.g., pyxb.utils.saxdom) into another (e.g., xml.dom.minidom).

appendChild(self, child, parent)

source code 

Add the child to the parent.

Parameters:
  • child (xml.dom.Node) - The value to be appended
  • parent (xml.dom.Node) - The new parent of the child
Returns: xml.dom.Node

Note: If the child and the parent use different DOM implementations, this operation will clone the child into a new instance, and give that to the parent.


Class Variable Details [hide private]

__NamespaceContext

Value:
<pyxb.namespace.resolution.NamespaceContext object>