Skip to main content

python module to Down Translate XML

Project description

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.)

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

xmldt-0.0.9.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

xmldt-0.0.9-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file xmldt-0.0.9.tar.gz.

File metadata

  • Download URL: xmldt-0.0.9.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for xmldt-0.0.9.tar.gz
Algorithm Hash digest
SHA256 af1b57debb142796007e0e813d6dbca266a7fdd40c9bf72d158fd0ad7554ee55
MD5 0035c1a6378fc109872f19fb2a32e223
BLAKE2b-256 858f6cd401c8c94a55d1115394f7feb8a1a957b2b06f3136a7300fd5a1a91434

See more details on using hashes here.

File details

Details for the file xmldt-0.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: xmldt-0.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for xmldt-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0505c1a126e0a9135f3ba8695f4d7a9f7f59d979d24b113f68b5ab3d56ee4a45
MD5 f897c8323d49934452773b49676199e5
BLAKE2b-256 695491316a28bc24cbb2bdf9291370df7195dcbe17492fa7625f6f0e27d503e5

See more details on using hashes here.

Supported by

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