gws.lib.xmlx.parser¶
Expat-based XML parser.
Source code: gws.lib.xmlx.parser
Module Contents¶
- gws.lib.xmlx.parser.from_path(path: str, opts: gws.XmlOptions | None = None) gws.XmlElement¶
Parse an XML file.
- Parameters:
path – Path to the file.
opts – Parsing options (
removeNamespaces,compactWhitespace).
- Returns:
The root element.
- Raises:
ParseError – If the document is malformed, contains entity declarations or cannot be decoded.
- gws.lib.xmlx.parser.from_string(inp: str | bytes, opts: gws.XmlOptions | None = None) gws.XmlElement¶
Parse an XML document from a string or bytes.
Bytes are decoded as UTF-8, then with the declared encoding, then as Latin-1.
- Parameters:
inp – The document as a string or bytes.
opts – Parsing options (
removeNamespaces,compactWhitespace).
- Returns:
The root element.
- Raises:
ParseError – If the document is malformed, contains entity declarations or cannot be decoded.