Skip to main content

xmldt - a Python module to process XML/HTML files in natural way

Synopsis

pydt file.xml > proc.py

from xmldt import XmlDt

pydt script

pydt is used to bootstrap the processing task

xmldt variables and functions

class proc(XmlDt):      # or class proc(HtmlDt) for HTML


proc(strip=True,        # _flags dictionary
     empty=False,            # keep spaces
     ns_strip= ???

proc(filename="x.xml")
  • __defaul__(s,ele)

  • __pcdata__(s,text)

  • __comment__(s,txt)

  • __end__(s,result)

  • __join__(s,ele)

  • @XmlDt.dt_tag("id-id")\ndef id_id(s, e):....

toxml function

    toxml("foo", {})                     == "<foo/>"
    toxml("foo", {"a": "b"})             == "<foo a=\"b\"/>"
    toxml("foo", {}, "bar")              == "<foo>bar</foo>"
    toxml("foo", {}, {"a": "b", "c": "d"}) == "<foo><a>b</a><c>d</c></foo>"
    toxml("foo", {}, ["a", "b"])         == "<foo>a</foo><foo>b</foo>"
    toxml("foo", {"a": "b"}, ["a", "b"]) == "<foo a=\"b\">a</foo><foo a=\"b\">b</foo>"
    toxml("foo", {}, ["a", "b"], ["c"])  == "<foo><item>a</item><item>b</item><item>c</item></foo>"

Function Class Element

   ele = Element("tag", {"c":"d"}, "contents")
   ele.xml                      "<tag c='d'>contents</tag>"
   ele.toxml(v={"a":"b"})       "<tag a='b'>contents</tag>"
   ele.tag        ele.tag="val"            or ele.q
   ele.contents   ele.c = """.... """      or ele.c
   ele["att"]   : value or None            ele.attrs or ele.v
   

element functions and methods

  • ele.parent : element or None
  • ele.parent.tag : tag-name
  • ele["root"]
  • ele["gparent"]
  • ele.in_context("tag1")
  • ele._dt

(DT)self functions and methods (usefull for example, in __pcdata__)

  • s._path or s.dt_path
  • s._parent or s.dt_parent = s._path[-1]
  • s._gparent or s.dt_gparent = s._path[-2]
  • s._root or s.dt_root = s._path[0]

types

_types = { 'table' : 'list', 'tr' : 'list', 'td' : 'list' }

Valid types are

  • zero -- return "" and skip processing subtree
  • list -- list of the subelement values
  • map -- map subelement-tags to their values
  • mmap -- map subelement-tags to the list of their values
  • mmapwn -- multimap when necessary (more than one ocor.)

Metadata

Release files for xmldt 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xmldt 0.0.13
File Size Uploaded
xmldt-0.0.13.tar.gz 71.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xmldt 0.0.13
File Interpreter ABI Platform
xmldt-0.0.13-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 81.9 kB

Release files / xmldt-0.0.13.tar.gz

Download URL xmldt-0.0.13.tar.gz
Size 71.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b6ff2e547800ffc7a8d2289c1bcfd377e1ced875fb6dd098a5a6a9cdf89b0216
BLAKE2b-256 checksum
How to use checksums
e53bd65df3d9bbd8213e9269c17bef76b0305aad0ad83dc1ff6a5167c3db32fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / xmldt-0.0.13-py2.py3-none-any.whl

Download URL xmldt-0.0.13-py2.py3-none-any.whl
Size 10.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9fcd1ce7d703af5a9eb35c5d9b5f3c8c77bafcf643f649ac0242492c4be6dc69
BLAKE2b-256 checksum
How to use checksums
293858ece3ba1132e95cc96a086547cb2167a9e5702e7d3b1ebf299a353ef231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page