XML

Concise generation of XML.
from IPython.display import Markdown
from pprint import pprint

source

XT

 XT (tag, cs, attrs=None, void_=False, **kwargs)

*Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.*


source

xt

 xt (tag:str, *c, void_=False, **kw)

Create an XML tag structure [tag,children,attrs] for toxml()

The main HTML tags are exported as xt partials.

Attributes are passed as keywords. Use ‘klass’ and ‘fr’ instead of ‘class’ and ‘for’, to avoid Python reserved word clashes.


source

Html

 Html (*c, doctype=True, **kwargs)

An HTML tag, optionally preceeded by !DOCTYPE HTML

samp = Html(
    Head(Title('Some page')),
    Body(Div('Some text', Input(name='me'), Img(src="filename", data=1), klass='myclass'))
)
pprint(samp)
(['!doctype', (), {'html': True}],
 ['html',
  (['head', (['title', ('Some page',), {}],), {}],
   ['body',
    (['div',
      ('Some text',
       ['input', (), {'name': 'me'}],
       ['img', (), {'data': 1, 'src': 'filename'}]),
      {'class': 'myclass'}],),
    {}]),
  {}])

The three elements of the list can also be accessed with property names, so you don’t have to remember their order.

elem = P('Some text', id="myid")
print(elem.tag)
print(elem.children)
print(elem.attrs)
p
('Some text',)
{'id': 'myid'}

You can also get and set attrs directly:

elem.id = 'newid'
print(elem.id)
elem
newid
['p', ('Some text',), {'id': 'newid'}]

source

to_xml

 to_xml (elm, lvl=0)

Convert xt element tree into an XML string

h = to_xml(samp)
print(h)
<!doctype html>

<html>
  <head>
    <title>Some page</title>
  </head>
  <body>
    <div class="myclass">
Some text
      <input name="me"></input>
      <img src="filename" data="1"></img>
    </div>
  </body>
</html>

source

highlight

 highlight (s, lang='xml')

Markdown to syntax-highlight s in language lang


source

showtags

 showtags (s)

source

getattr

 __getattr__ (tag)