Socket
Socket
Sign inDemoInstall

xml-to-dict

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-to-dict

A simple Python XML to Dictionary parser


Maintainers
1

xml_to_dict

A simple Python XML to Dictionary parser.

The package is based on this answer from Stack Overflow. It parses entities as well as attributes following this XML-to-JSON "specification".

I just added the from_nest function, which lets you retrieve a value from the nested dictionaries.

Install

pip3 install xml_to_dict --user

Usage

from xml_to_dict import XMLtoDict

sample_xml = (
    '<response>'
        '<results>'
            '<user>'
                '<name>Ezequiel</name>'
                '<age>33</age>'
                '<city>San Isidro</city>'
            '</user>'
            '<user>'
                '<name>Belén</name>'
                '<age>30</age>'
                '<city>San Isidro</city>'
            '</user>'
        '</results>'
    '</response>'
)

parser = XMLtoDict()

print(parser.parse(sample_xml)) # {'response': {'results': {'user': [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}

print(parser.value_from_nest('.*ser', sample_xml)) # [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch
  3. Commit your Changes
  4. Push to the Branch
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc