Skip to main content

xmlplain

XML as plain object utility module

Build Status

Synopsys

This module is a set of utility functions for parsing XML input into plain list/dict/string types.

These plain XML objects in turn can be emitted through YAML for instance as bare YAML without python objects.

The motivating usage is to dump XML to YAML, manually edit files as YAML, and emit XML output back.

The original XML file is supposed to be preserved except for comments and (if requested) spaces between non-leaf elements.

Note that there are alternative modules with nearly the same functionality, but none of them both provide simple plain objects and preserve the initial XML content even for non structured XML.

WARNING: the implementation does not support XML namespaces and entity location. If this is found useful, please add an issue.

Usage

In order to convert a XML file to a YAML representation, for instance given the tests/example-1.xml file:

<example>
  <doc>This is an example for xmlobj documentation. </doc>
  <content version="beta">
    <kind>document</kind>
    <class>example</class>
    <structured/>
    <elements>
      <item>Elt 1</item>
      <doc>Elt 2</doc>
      <item>Elt 3</item>
      <doc>Elt 4</doc>
    </elements>
  </content>
</example>

Execute the following python3 code:

import xmlplain

# Read to plain object
with open("tests/example-1.xml") as inf:
  root = xmlplain.xml_to_obj(inf, strip_space=True, fold_dict=True)

# Output plain YAML
with open("example-1.yml", "w") as outf:
  xmlplain.obj_to_yaml(root, outf)

This will output the YAML representation in example-1.yml:

example:
  doc: 'This is an example for xmlobj documentation. '
  content:
    '@version': beta
    kind: document
    class: example
    structured: ''
    elements:
    - item: Elt 1
    - doc: Elt 2
    - item: Elt 3
    - doc: Elt 4

One can then read the emitted YAML representation and generate again an XML output with:

import xmlplain

# Read the YAML file
with open("example-1.yml") as inf:
  root = xmlplain.obj_from_yaml(inf)

# Output back XML
with open("example-1.new.xml", "w") as outf:
  xmlplain.xml_from_obj(root, outf, pretty=True)

This will output back the following XML (there may be some indentation and/or short empty elements differences w.r.t. the original):

<?xml version="1.0" encoding="UTF-8"?>
<example>
  <doc>This is an example for xmlobj documentation. </doc>
  <content version="beta">
    <kind>document</kind>
    <class>example</class>
    <structured></structured>
    <elements>
      <item>Elt 1</item>
      <doc>Elt 2</doc>
      <item>Elt 3</item>
      <doc>Elt 4</doc>
    </elements>
  </content>
</example>

For a detailled usage, read the API documentation with:

pydoc xmlplain

Or get to the online documentation at: https://guillon.github.io/xmlplain

Download

Download this module archives from the releases at: https://github.com/guillon/xmlplain/releases

Or get the git repository at: https://github.com/guillon/xmlplain

Requirements

The module is compatible with python 2.6/2.7 and python 3.x.

It depends upon the folowing modules:

sudo pip install --user setuptools PyYAML

On deb systems one may install these modules with:

sudo apt-get install python-setuptools python-yaml

Installation

Either copy the xmlplain.py file somewhere or install it with setup.py.

For a user local installation (installs to $HOME/.local) do:

./setup.py install --user

For a system level installation do:

./setup.py build
sudo ./setup.py install

Unitary tests

This module is delivered as part of a source tree with tests, in order to run tests, do for instance:

make -j16 check

Documentation

The documentation is generated with sphinx as is:

make doc

Install sphinx with:

pip install sphinx

Or on deb systems:

sudo apt-get install python-sphinx

The online documentation is hosted at: https://guillon.github.io/xmlplain

License

This is free and unencumbered software released into the public domain.

Metadata

Release files for xmlplain 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xmlplain 1.0.2
File Size Uploaded Provenance Actions
xmlplain-1.0.2.tar.gz 26.8 kB Without provenance Details for xmlplain-1.0.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for xmlplain 1.0.2
File Interpreter ABI Platform Actions
xmlplain-1.0.2-py3-none-any.whl Python 3 none any Details for xmlplain-1.0.2-py3-none-any.whl
xmlplain-1.0.2-py2-none-any.whl Python 2 none any Details for xmlplain-1.0.2-py2-none-any.whl

Total release size: 46.7 kB

Release files / xmlplain-1.0.2.tar.gz

Download URL xmlplain-1.0.2.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9e5a5ef63b5c16c0e0424456aa0a820a36e4b29fee8b23780e4247b14bb6e1fe
BLAKE2b-256 checksum
How to use checksums
8ecfe19e3ee6265b15e17b501593acbcb3cdf1de543accd2a80af9bd1a0d6ef9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.5.2

Release files / xmlplain-1.0.2-py3-none-any.whl

Download URL xmlplain-1.0.2-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
daf38489d3575fbd1099581d32c5fcb63377af11c46a636e0f1de1c98953e83b
BLAKE2b-256 checksum
How to use checksums
eda84ac27115bc33d43c21a03f81bc2482161769bbe7d59a5ea475c497b7c8db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.5.2

Release files / xmlplain-1.0.2-py2-none-any.whl

Download URL xmlplain-1.0.2-py2-none-any.whl
Size 10.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
a1e719348fb7e85b44373a92dd7fe757cb77e50c1ce8aacfff6c88c977ec8aeb
BLAKE2b-256 checksum
How to use checksums
9df592c1fddb51a387148277a7e8b0e8360d7fbd749241332e42c3f296825b02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.12

Security for xmlplain 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page