Quick Start¶
A five-minute tour of pygixml: parse a string, read a value, and save it back out. For the full picture (navigating, XPath, streaming, the higher-level modules), see the pages linked in Next Steps below.
import pygixml
xml = '''
<library>
<book id="1" category="fiction">
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<year>1925</year>
</book>
</library>
'''
doc = pygixml.parse_string(xml)
root = doc.root
book = root.child("book")
print(book.attribute("id").value) # 1
print(book.child("title").text()) # The Great Gatsby
# Create and save
doc = pygixml.XMLDocument()
root = doc.append_child("catalog")
root.append_child("item").set_value("Hello")
doc.save_file("output.xml")
Tip
Use ParseFlags to control parsing speed vs strictness.
ParseFlags.MINIMAL skips escape processing and whitespace handling for
maximum throughput. See Parse Flags for details.
Next Steps¶
Learn the full DOM API: navigating, iterating, creating, modifying, and XPath, in DOM Parser
Reading huge files without loading them whole: Streaming: Constant-Memory Parsing for Big XML
Dotted-navigation, dict, and JSON views of the same tree, in Objectify: Dotted Navigation, Dictify: XML to Dict, and Jsonify: XML to JSON
The command-line tools, in Command Line Tools
Practical, runnable examples, in Examples
The full API reference
How fast this all actually is: Performance