from yattag import Doc doc, tag, text = Doc().tagtext() with tag('html'): with tag('head'): with tag('title'): text('Sample HTML document') with tag('body'): with tag('p'): text('Hello, Yattag!') result = doc.getvalue() print(result)
from yattag import Doc doc, tag, text = Doc().tagtext() with tag('person'): with tag('name'): text('John') with tag('age'): text('30') with tag('city'): text('New York') result = doc.getvalue() print(result)This code generates an XML snippet with a person's name, age, and city. The `with tag` statements create new tags, and `text` adds text to the tag. Overall, yattag is a Python package library for generating HTML and XML markup.