smartXML package enables you to read, search, manipulate, and write XML files with ease
Project description
smartXML
The smartXML package enables you to read, search, manipulate, and write XML files with ease.
The API is designed to be simple, but it will be enhanced according to usage and requests.
The package includes a SmartXML representing the XML file, and ElementBase representing each element in the XML tree
SmartXML:
- properties:
root: the root element of the XML filedeclaration: the XML declaration (e.g.,<?xml version="1.0" encoding="UTF-8"?>)
- methods:
read: reads the XML file from the root elementwrite: writes the XML to a filefind: finds elements from the root element
ElementBase: (base class for Element, Comment, TextOnlyComment, CData, and Doctype)
- properties:
name: the name of the elementparent: the parent element
- methods:
find: finds elements from the current elementremove: removes the current element from its parentcomment_out: comments out the current elementadd_before: adds an element before the current elementadd_after: adds an element after the current elementadd_as_son_of: adds an element as a son of the current elementset_as_parent_of: sets the current element as the parent of another elementto_string: converts the current element to a string
Usage Example
from pathlib import Path
from smartxml import SmartXML, TextOnlyComment
input_file = Path('./example.xml')
xml = SmartXML(input_file)
firstName = xml.find('students|student|firstName', with_content='Bob')
bob = firstName.parent
bob.comment_out()
header = TextOnlyComment('Bob is out')
header.add_before(bob)
xml.write()
result (example.xml):
<students>
<!-- Bob is out -->
<!--
<student id="S002">
<firstName>Bob</firstName>
<lastName>Levi</lastName>
</student>
-->
</students>
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 smartxml-1.0.6.tar.gz.
File metadata
- Download URL: smartxml-1.0.6.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5e71fbbeff7da16279296f6e68644622952f13cb24d600c32305b9447045e46
|
|
| MD5 |
53935ceee611629e7c187df86920b197
|
|
| BLAKE2b-256 |
d80d60874e506a35241b3a3e116bbeb3d8c7630d83cd741a1715dc10566a8395
|
File details
Details for the file smartxml-1.0.6-py3-none-any.whl.
File metadata
- Download URL: smartxml-1.0.6-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a1f170599284a500e619df09f22091e49c1ddd68883e0e71ce61a20f74e15f0
|
|
| MD5 |
ecb10910a9d00bfd4557814fad37b4ea
|
|
| BLAKE2b-256 |
ce926217ecea2e5292c73482db57389f71c34282e6042c78e8f4740a73d56888
|