Skip to main content

AnyXml

A minimal reimplementation of ET.tostring that supports unescaped "raw" text content.

The standard library's ET.tostring always XML-escapes the text/tail content of elements (e.g. <, &), which makes it impossible to inject pre-built, already-valid XML fragments (or other raw strings) during serialization. This class provides :meth:tostring, which behaves similarly to ET.tostring but additionally supports:

  • Strings wrapped in :class:RawText are emitted verbatim during serialization, without any escaping; regular str text is still escaped according to XML rules.
  • Comment nodes (ET.Comment) and processing instruction nodes (ET.ProcessingInstruction) are rendered as <!--...--> and <?...?> respectively.
  • Elements with no text and no children are rendered as self-closing tags (<tag/>).

Example

>>> el = ET.Element("p")
>>> el.text = AnyXml.RawText("<b>bold</b>")
>>> AnyXml.tostring(el)
'<p><b>bold</b></p>'

Download files

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

Source Distribution

anyxml-0.1.0.tar.gz (1.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anyxml-0.1.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file anyxml-0.1.0.tar.gz.

File metadata

  • Download URL: anyxml-0.1.0.tar.gz
  • Upload date:
  • Size: 1.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anyxml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d39aa376bb770f3f140086f7ab9756e12912b850700428780c3efc5f506fb00
MD5 28e8cf834063b0454050184cc55658c5
BLAKE2b-256 53cc5cea09e7969c9171445012d8507a428f38d7d7aaedb81c57aee3ee5a8a7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyxml-0.1.0.tar.gz:

Publisher: publish.yml on BHznJNs/anyxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anyxml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: anyxml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anyxml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c5c99b26cb3d4de91b277fdfdc1a0181376bc387a978390429644c5087d502e
MD5 519653ad77ee8ce16b61ff8bb4e58a2c
BLAKE2b-256 3cc03c9df7fc59b6be46a400d7782c614213a53f4e2ff986c279ccc04e0eb57c

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyxml-0.1.0-py3-none-any.whl:

Publisher: publish.yml on BHznJNs/anyxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page