xml_utils.py

About this file

We attempted to read from templates/app_lib_onelogin_saml2_xml_utils.py_hw.txt but failed.

Code Check Report


No problems to report
                        

Documentation drawn from source code

OneLogin_Saml2_XML class

Copyright (c) 2010-2018 OneLogin, Inc.
MIT License

Auxiliary class of OneLogin's Python Toolkit.


OneLogin_Saml2_XML(object):

to_string(xml, **kwargs):

Serialize an element to an encoded string representation of its XML tree.
:param xml: The root node
:type xml: str|bytes|xml.dom.minidom.Document|etree.Element
:returns: string representation of xml
:rtype: string

to_etree(xml):

Parses an XML document or fragment from a string.
:param xml: the string to parse
:type xml: str|bytes|xml.dom.minidom.Document|etree.Element
:returns: the root node
:rtype: OneLogin_Saml2_XML._element_class

validate_xml(xml, schema, debug=False):

Validates a xml against a schema
:param xml: The xml that will be validated
:type xml: str|bytes|xml.dom.minidom.Document|etree.Element
:param schema: The schema
:type schema: string
:param debug: If debug is active, the parse-errors will be showed
:type debug: bool
:returns: Error code or the DomDocument of the xml
:rtype: xml.dom.minidom.Document

query(dom, query, context=None):

Extracts nodes that match the query from the Element

:param dom: The root of the lxml objet
:type: Element

:param query: Xpath Expresion
:type: string

:param context: Context Node
:type: DOMElement

:returns: The queried nodes
:rtype: list

cleanup_namespaces(tree_or_element, top_nsmap=None, keep_ns_prefixes=None):

Keeps the xmlns:xs namespace intact when etree.cleanup_namespaces is invoked.
:param tree_or_element: An XML tree or element
:type tree_or_element: etree.Element
:param top_nsmap: A mapping from namespace prefixes to namespace URIs
:type top_nsmap: dict
:param keep_ns_prefixes: List of prefixes that should not be removed as part of the cleanup
:type keep_ns_prefixes: list
:returns: An XML tree or element
:rtype: etree.Element

extract_tag_text(xml, tagname):

element_text(node):

Source code