from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html'): with tag('head'): with tag('title'): text('My Page Title') with tag('body'): with tag('h1'): text('Welcome to my website.') with tag('p'): text('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') html = doc.getvalue() print(html)
from yattag import Doc doc, tag, text = Doc().tagtext() with tag('root'): for i in range(5): with tag('item'): text(f'item {i}') xml = doc.getvalue() print(xml)This example shows the usage of the yattag library to generate an XML document which includes a root tag and five item tags containing a text value. The getvalue() method is called at the end of the code to get the generated XML code as a string. Package library: yattag