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:
    • tree: 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
    • to_string: converts the entire XML tree to a string

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
    • to_string: converts the current element to a string
    • get_path: gets the path as a string from the root of the XML tree, separated by |
    • is_comment : returns True if the element is a comment
    • add_before: adds an element before the current element
    • add_after: adds an element after the current element
    • add_as_last_son_of: adds an element as the last son of the current element

Usage Example

from pathlib import Path
from smartXML.xmltree import SmartXML, TextOnlyComment

input_file = Path('files/students.xml')
xml = SmartXML(input_file)

first_name = xml.find('students|student|firstName', with_content='Bob')
bob = first_name.parent
bob.comment_out()
header = TextOnlyComment('Bob is out')
header.add_before(bob)

xml.write()

result (files/students.xml):

<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.16.tar.gz (15.0 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.16-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartxml-1.0.16.tar.gz
  • Upload date:
  • Size: 15.0 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.16.tar.gz
Algorithm Hash digest
SHA256 31e8b2243459498076a0ddf6a21df1fd103e93f35dad3862b552da2ec05c8982
MD5 f03c438904207458b76f856bd9cc8744
BLAKE2b-256 682063296b6a738c5194284cc4485bac742976d12c04be957931b1d4b3feeddb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartxml-1.0.16-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

Hashes for smartxml-1.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 833ca8b3425bfe43209893b387bc11bb6c2257baa24fcc282db9a27f8783d2ec
MD5 c64bd7fe5c6fb2e68608f4a7735ef38b
BLAKE2b-256 0e64d71683084882bce80a873165d161cc03503c8bb55b62c94dd708d8ede3d4

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