Simple XML parser without tag structure validation
Project description
xml7shi
A pull-based simple and permissive XML parser for Python.
Features
- Focuses on practical parsing rather than strict XML specification compliance
- No external dependencies
Installation
pip install xml7shi
Usage
import xml7shi
# Parse XML string
xml = '''<?xml version="1.0" encoding="UTF-8"?>
<root>
<item id="1">First item</item>
<item id="2">Second item</item>
</root>'''
# Create reader instance
xr = xml7shi.reader(xml)
# Iterate through each 'item' element
for _ in xr.each("item"):
id = xr["id"]
# Read the content of the current element
if xr.read():
print(f"ID: {id}, Content: {xr.text}")
Notes:
- The reader instance
xris stateful; its internal state changes with each read operation
API Reference
xml7shi.reader: Main parser class that reads XML content.
Methods:
read(): Read next elementfind(tag, **kwargs): Find next element matching tag and attributeseach(tag="", **kwargs): Returns a generator that iterates over elements matching the tag and attributes
Notes:
kwargsis a dictionary of attribute names and values to match in the element. For example,find("item", id="1")will find the next<item>element with matching attributes
Specifications
For detailed behavior, please refer to examples/tag.py.
Parser Behavior:
- The parser is permissive and does not perform strict XML syntax checking
- The parser attempts to parse incomplete XML as much as possible
Tag Processing:
- Self-closing tags like
<tag/>are treated as separate opening and closing tags, i.e.,<tag></tag>. - Tag names are converted to lowercase (case-insensitive)
- Tag hierarchy is not recognized; nested tags must be processed by the user
Attribute Handling:
- Attribute values can be processed with or without quotes (e.g., both
a=3anda="3"are valid) - Spaces between attribute names and values are allowed (e.g.,
a = 3) - All attribute values are treated as strings
Content Processing:
- Text content is decoded using html.unescape() to handle HTML entities
- Comments are stored in the values dictionary with the
commentkey - Comment tags are treated as empty tag names
Developer Notes
For developers, it is recommended to use pypa/build and pypa/installer for building and installing this package.
Building:
pip install build
python -m build
This will generate wheel and source distribution files in the dist directory.
Installing:
pip install installer
python -m installer dist/*.whl
Alternatively, you can use pip to install the wheel file directly:
pip install dist/*.whl
Using these standard tools ensures a more reliable and reproducible build and installation process.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xml7shi-0.1.0.tar.gz.
File metadata
- Download URL: xml7shi-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edcb0647b303eb1415fe613263a42d4411659f7063d49ff583c8e827e70be785
|
|
| MD5 |
54ccaa6649ef52465f48221fefe9895d
|
|
| BLAKE2b-256 |
5bed167c4615abc4c2808a579d778997594181cd282453501ae309f92522a8c0
|
File details
Details for the file xml7shi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xml7shi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcc88dca0ce25cb48489584f7fc3ef32babce1f159a67ee5fe377f16020fc5bb
|
|
| MD5 |
dd09ca853f8a6faf7b641b9902492a1a
|
|
| BLAKE2b-256 |
7bac1495300ad2266a7e5d5ad80270a7c611e1232bddba8b4ab7b141392626d2
|