Skip to main content

Transforms a python structure to an xml element with lxml

Project description

Requirements

  • python 3.4

  • lxml 3.4.4

Install

pip install lxml-element-maker

Usage

Transforms a python structure to an xml element with lxml :

from element_maker.utils import XMLElement

structure = {'ArchiveTransferRequest':
                      [
                          [
                              {'Comment': [
                                  ['baz'], {"foo": "bar"}
                              ]
                              },
                              {'Date': [
                                  ["2014-05-12T00:00:00Z"]
                              ]
                              }
                          ],
                          {"cars": "pizza"}
                      ]
                      }
namespace = "fr:gouv:culture:archivesdefrance:seda:v1.0"
xml_element = XMLElement(namespace=self.namespace, **self.structure)()
# Test the element with an xsd schema
result = xml_element.pass_xsd("./tests/data/test.xsd")
# Or test the element with an rng schema
result2 = xml_element.pass_rng("./tests/data/test.rng")

The result is an xml :

<ArchiveTransferRequest xmlns="fr:gouv:culture:archivesdefrance:seda:v1.0" cars="pizza">
    <Comment foo="bar">baz</Comment>
    <Date>2014-05-12T00:00:00Z</Date>
</ArchiveTransferRequest>

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

lxml_element_maker-1.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file lxml_element_maker-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lxml_element_maker-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5343c2a0373ceab19c5d544f884fedf510705a53d66578c2ad07c0b629fcef4
MD5 8ea766ebf9c7c89902cf29d5466d29a4
BLAKE2b-256 62d91a26789da94e06a9587554ea646bfd8f14e921ee57061129e27173cdbb95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page