Parser¶
pybeerxml.parser.Parser
¶
Reads BeerXML files or strings and returns a list of Recipe objects.
A single BeerXML document may contain multiple <RECIPE> elements; all
parse methods always return a list. Unknown XML fields are silently
ignored so that non-standard files do not raise.
Examples:
>>> from pybeerxml import Parser
>>> parser = Parser()
>>> recipes = parser.parse("recipe.beerxml")
>>> for recipe in recipes:
... print(recipe.name, recipe.og)
parse(xml_file)
¶
Parse a BeerXML file from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_file
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
list[Recipe]
|
A list of |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValidationError
|
If the file is not valid XML or does not match the BeerXML schema. |
parse_from_string(xml_string)
¶
Parse BeerXML content from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_string
|
str
|
A valid BeerXML document as a string. |
required |
Returns:
| Type | Description |
|---|---|
list[Recipe]
|
A list of |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
parse_tree(tree)
¶
Parse an already-constructed ElementTree.
Useful when you need full control over XML loading (e.g. custom encoding handling).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
ElementTree[Any]
|
A parsed XML tree. |
required |
Returns:
| Type | Description |
|---|---|
list[Recipe]
|
A list of |