Did I find the right examples for you? yes no

All Samples(10)  |  Call(5)  |  Derive(0)  |  Import(5)
Convert an XML tree to a dictionary.

:param paths: An optional list of XPath expressions applied on the XML tree.
:param nsmap: An optional prefix-namespace mapping for conciser spec of paths.
:param strip_ns: Flag for whether to remove the namespaces from the tags.

        def xml_to_dict(tree, paths=['.//'], nsmap={}, strip_ns=False):
    """Convert an XML tree to a dictionary.

    :param paths: An optional list of XPath expressions applied on the XML tree.
    :param nsmap: An optional prefix-namespace mapping for conciser spec of paths.
    :param strip_ns: Flag for whether to remove the namespaces from the tags.
    """
    fields = defaultdict(list)
    for path in paths:
        elements = tree.findall(path, nsmap)
        for element in elements:
            tag = element.tag
            if strip_ns:
                tag = re.sub(r'\{.*\}', '', tag)
            fields[tag].append(element.text)
    return dict(fields)
        


src/s/i/Sickle-0.3/sickle/models.py   Sickle(Download)
 
from lxml import etree
from .utils import get_namespace, xml_to_dict
 
 
    def __init__(self, identify_response):
        super(Identify, self).__init__(identify_response.xml, strip_ns=True)
        self.xml = self.xml.find('.//' + self._oai_namespace + 'Identify')
        self._identify_dict = xml_to_dict(self.xml, strip_ns=True)
        for k, v in self._identify_dict.items():
            # in the ``oai_dc`` case.
            self.metadata = xml_to_dict(
                self.xml.find(
                    './/' + self._oai_namespace + 'metadata'
                ).getchildren()[0], strip_ns=self._strip_ns)
    def __init__(self, set_element):
        super(Set, self).__init__(set_element, strip_ns=True)
        self._set_dict = xml_to_dict(self.xml, strip_ns=True)
        for k, v in self._set_dict.items():
            setattr(self, k.replace('-', '_'), v[0])
    def __init__(self, mdf_element):
        super(MetadataFormat, self).__init__(mdf_element, strip_ns=True)
        #: The prefix of this format.
        self._mdf_dict = xml_to_dict(self.xml, strip_ns=True)
        for k, v in self._mdf_dict.items():

src/p/y/pyBlueVia-0.1.0/bluevia/base_api.py   pyBlueVia(Download)
from requests.auth import HTTPBasicAuth
 
from .utils import OAuth2, build_mms_body, parse_mms_body, xml_to_dict, sanitize
from .exceptions import APIError, AccessTokenError, ContentTypeError
 
        elif content_type.startswith('application/xml'):
            try:
                sms = xml_to_dict(content, ('id', 'from', 'to', 'message', 'timestamp'))
            except KeyError:
                raise ValueError('Bad XML content')

src/d/j/django-authorizenet-HEAD/tests/tests/views.py   django-authorizenet(Download)
from authorizenet.models import CustomerProfile, CustomerPaymentProfile
 
from .utils import create_user, xml_to_dict
from .mocks import cim_url_match, customer_profile_success, \
    payment_profile_success

src/d/j/django-authorizenet-HEAD/tests/tests/models.py   django-authorizenet(Download)
from authorizenet.models import CustomerProfile
 
from .utils import create_user, xml_to_dict
from .mocks import cim_url_match, customer_profile_success, delete_success
from .test_data import create_empty_profile_success, delete_profile_success

src/d/j/django-authorizenet-HEAD/tests/tests/cim.py   django-authorizenet(Download)
    add_profile
 
from .utils import xml_to_dict
from .mocks import cim_url_match, customer_profile_success
from .test_data import create_profile_success