Builders FAQ
Basic Questions
What’s the difference between a builder and a Bag?
Bag: General-purpose hierarchical container
Builder: Adds domain-specific methods and validation rules to a Bag
Why do methods like div() return a Bag, but p() returns a BagNode?
Elements with allowed children (containers) return a Bag so you can add children. Elements without children (leaves) return the BagNode itself.
How do I access the node value?
How do I access node attributes?
Labels and Paths
Why are labels like div_0, div_1?
Auto-generated labels use tag_index format for uniqueness:
How do I use custom labels?
Use node_label:
How do I find elements by tag?
Validation
When does validation happen?
At build time - invalid children are rejected immediately:
How do I check for errors after building?
Use builder.validate():
Can I disable validation?
Not directly, but you can use plain Bag for unstructured content.
Output Generation
How do I generate HTML/XML?
Use bag.to_xml():
How do I generate Markdown?
Use build() + render():
Custom Builders
How do I create a simple builder?
How do I add custom parameters?
Add parameters to the method signature: