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_last_son_of: adds an element as the last son of the current element
    • to_string: converts the current element to a string

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 (example.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.15.tar.gz (14.9 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.15-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartxml-1.0.15.tar.gz
  • Upload date:
  • Size: 14.9 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.15.tar.gz
Algorithm Hash digest
SHA256 33f3e90909ea6711e633126e62129a7bb963072b15e3c039db95c2d39b141d0b
MD5 bbee34a4d30eab1d909f26a6ff12eed7
BLAKE2b-256 74995aeb129b214b74d197941043ee63e7cf285fdf6674e85bbc4aec0e13d8a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartxml-1.0.15-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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.15-py3-none-any.whl
Algorithm Hash digest
SHA256 ab69e82c95f0f1e889048fb93df7f1f56237de5d47ace9843c8ca0effd84b7b6
MD5 4f14765d8603e3548a33db20ac18d122
BLAKE2b-256 f5177e717c0f6e9037d3b52aeb61d6dda4e79a057bf4778265e228f753db45e1

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