Last active
October 5, 2015 14:38
-
-
Save walkerdb/b97d8c3d9480b29256b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import the part of the library you'll need | |
| >>> from lxml.builder import E | |
| # the basic format for using E is: | |
| # E.[name of tag]([tag text], [attribute name]=[attribute value], [anything else that comes inside the tag]) | |
| # A single-tag example: | |
| >>> new_element = E.extent("25 photographs", encodinganalog="300") | |
| # printing to see the results | |
| >>> print(etree.tostring(new_element)) | |
| '<extent encodinganalog="300">25 photographs</extent>' | |
| # Complex tag-building with the E tool: | |
| >>> element = E.did( | |
| E.unittitle("Ann Arbor Superheroes"), | |
| E.container("Box 1", type="box"), | |
| E.physdesc( | |
| E.extent("25 photographs", encodinganalog="300"), | |
| altrender="whole" | |
| ) | |
| ) | |
| # the results | |
| >>> print(etree.tostring(element, pretty_print=True)) | |
| ''' | |
| <did> | |
| <unittitle>Ann Arbor Superheroes</unittitle> | |
| <container type="box">Box 1</container> | |
| <physdesc altrender="whole"> | |
| <extent encodinganalog="300">25 photographs</extent> | |
| </physdesc> | |
| </did> | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment