Skip to main content

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 file
    - `declaration`: the XML declaration (e.g., `<?xml version="1.0" encoding="UTF-8"?>`)
- methods:
    - `read`: reads the XML file from the root element
    - `write`: writes the XML to a file
    - `find`: finds elements from the root element

ElementBase: (base class for Element, Comment, TextOnlyComment, CData, and Doctype)

- properties:
    - `name`: the name of the element
    - `parent`: the parent element
- methods:
    - `find`: finds elements from the current element
    - `remove`: removes the current element from its parent
    - `comment_out`: comments out the current element
    - `add_before`: adds an element before the current element
    - `add_after`: adds an element after the current element
    - `add_as_son_of`: adds an element as a son of the current element
    - `set_as_parent_of`: sets the current element as the parent of another element
    - `to_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:

<students>
  <!-- Bob is out -->
  <!--
    <student id="S002">
	  <firstName>Bob</firstName>
	  <lastName>Levi</lastName>
    </student>
  -->
</students>

Project details


Download files

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

Source Distribution

smartxml-1.0.3.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

smartxml-1.0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file smartxml-1.0.3.tar.gz.

File metadata

  • Download URL: smartxml-1.0.3.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for smartxml-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3291895b76485d54b103d945d3e9f2616122a44f4b0a38ffff072886769c4863
MD5 6ba6892d824103fc3db0c0a32c7bac5c
BLAKE2b-256 7a35c8f38ee798bd4aa514ae37aee3d1d241b1b3d297a1310d0242c982a9364a

See more details on using hashes here.

File details

Details for the file smartxml-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: smartxml-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for smartxml-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 79f54108b45af8b75159b8685b3f1e0cb533e59084e2d111c737119145c3a9b2
MD5 2c56757f86ca8cc8f6c7ab2f89fb0ae2
BLAKE2b-256 7925c01d6654c79fe6c71ded5d09607b00b139a31d0691a7f005827c6c6ab867

See more details on using hashes here.

Supported by

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