Skip to main content

myxmltools

Python PyPI Build Style

Small utility library to read and update XML nodes using xml.dom.minidom.

Installation

Requirements

  • Python 3.10+

Option 1: Install from local source with pip

pip install .

Option 2: Use Poetry (development setup)

poetry install

Usage

import xml.dom.minidom as md

from myxmltools import (
	getValue,
	getValues,
	getAttribute,
	tagExists,
	updateXML,
	updateOrCreateXML,
	setAttribute,
	removeTag,
	pretty_print,
)

doc = md.parseString(
	"""
	<root>
		<name id="42">John Doe</name>
		<age>30</age>
		<name id="99">Jane Doe</name>
	</root>
	"""
)

root = doc.documentElement

# Read values
first_name = getValue(root, "name")
all_names = getValues(root, "name")
name_id = getAttribute(root, "name", "id", idx=1)

# Update and create
updateXML(root, "age", 31)
updateOrCreateXML(root, "name", "Mark", idx=2)

# Attributes and removal
setAttribute(root, "age", "unit", "years")
removeTag(root, "name", idx=0)

# Check existence and pretty print
exists = tagExists(root, "age")
print(pretty_print(doc))

Functions

Reading

  • getValue(xml, label) Returns the text content of the first matching tag.

  • getFromXml(xml, label, idx=0) Returns the text content of the matching tag at index idx.

  • getValues(xml, label) Returns a list with text content for all matching tags.

  • getElement(xml, label, el=0) Returns the matching DOM element at index el.

  • getAttribute(xml, label, attribute, idx=0) Returns the value of attribute from the selected tag.

  • tagExists(xml, label) Returns True if at least one matching tag exists, otherwise False.

Writing

  • updateXML(xml, label, value, idx=0) Updates text content for an existing tag at index idx.

  • updateOrCreateXML(xml, label, value, idx=0) Updates the tag at index idx if it exists. If idx is exactly the next valid index, it appends a new tag.

  • setAttribute(xml, label, attribute, value, idx=0) Sets an attribute on the selected tag.

  • removeTag(xml, label, idx=0) Removes the selected tag from its parent node.

Formatting

  • pretty_print(dom) Returns an indented XML string with empty lines removed.

Notes

  • Functions raise descriptive exceptions for invalid labels, indices, attributes, or node types.
  • Most APIs accept both xml.dom.minidom.Document and xml.dom.minidom.Element.

Contributing

  1. Fork the repository and create a feature branch.
  2. Install development dependencies:
poetry install --with test,devel
  1. Run tests:
poetry run pytest
  1. Run lint checks:
poetry run ruff check .
  1. Open a pull request with a clear description of your change.

Changelog

0.2.0

  • Added robust validation and error handling for tag/attribute access.
  • Added indexed read and update operations for repeated tags.
  • Added updateOrCreateXML support for append-at-tail behavior.

Metadata

Release files for myxmltools 0.2.0

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

Source distribution (sdist)

Source distribution for myxmltools 0.2.0
File Size Uploaded Provenance
myxmltools-0.2.0.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for myxmltools 0.2.0
File Interpreter ABI Platform
myxmltools-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / myxmltools-0.2.0.tar.gz

Download URL myxmltools-0.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
da931099846fed4214d95c77a76fd6384c6ed2f9b8b9c9b2ccb0d04e80578abb
BLAKE2b-256 checksum
How to use checksums
ebf4850f366ebba615278b16c7585e0a173e5fcc6f7eeee8fa112d4a9dfd6d69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Linux/6.19.8-200.fc43.x86_64

Release files / myxmltools-0.2.0-py3-none-any.whl

Download URL myxmltools-0.2.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39f451b34276534832f368bb5d97291db637537a583b3e222202c1f7657f4be0
BLAKE2b-256 checksum
How to use checksums
676f41d4c3a2ecffb15f697920e9b9145d9ea70abba3d95015150fc3eb292603
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Linux/6.19.8-200.fc43.x86_64

Security for myxmltools 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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