Python for xmlsq¶
Perform simplified or full XPath 1.0 queries on an XML document.
Documentation¶
A Python interface to xmlsq <https://www.cryptosys.net/xmlsq/>.
-
class
xmlsq.Gen¶ General diagnostic info about the core library DLL.
-
static
compile_time()¶ Return date and time the core library DLL was last compiled.
-
static
core_platform()¶ Return the platform for which the core library DLL was compiled:
Win32orWin64.
-
static
module_name()¶ Return full path name of the current process’s core library DLL.
-
static
version()¶ Return the release version of the core library DLL as an integer value.
-
static
-
exception
xmlsq.Error(value)¶ Raised when a call to a core library function returns an error, e.g. unable to execute query, or some obviously wrong parameter is detected.
-
class
xmlsq.Opts¶ Option flags.
-
ASCIIFY= 4096¶ Asciify the output as XML character references [default=UTF-8-encoded].
-
DEFAULT= 0¶ Use default options.
-
RAW= 8192¶ Output nodeset in raw format [default=prettify with tabs and newlines].
-
TRIM= 16384¶ Trim leading and trailing whitespace (and collapse whitespace for an attribute value).
-
-
xmlsq.get_text(xmlfile, query, opts=0)¶ Extract text from the first matching XML node.
- Parameters
xmlfile (str) – Name of input XML file.
query (str) – XPath 1.0 expression to select a node. This must evaluate to a node or node set.
opts (Opts) – Option flags (add with ‘|’ operator).
- Returns
String containing the extracted text.
- Return type
str
- Remarks:
If query evaluates to a single element with content, then the text content will be output.
If query evaluates to an attribute, then the attribute value will be output.
If query evaluates to a node set, then the content of the first matching node will be returned as a string, including any markup.
If no matching node is found, an empty string
""is returned.No distinction is made between a match on an empty element and no match at all. Use
xmlsq.count()to differentiate between a match on an empty element (returns > 0) and no match at all (returns 0).
-
xmlsq.full_query(xmlfile, query, opts=0)¶ Perform a full XPath query on the XML input outputting the result as a string.
- Parameters
xmlfile (str) – Name of input XML file.
query (str) – XPath 1.0 expression.
opts (Opts) – Option flags (add with ‘|’ operator).
- Returns
The result of the full XPath 1.0 query as a string.
- Return type
str
- Remarks:
querymay be any valid XPath 1.0 expression. The result is always output as a string. So, for example, the number 1.5 will be output as the string “1.500000”.
-
xmlsq.count(xmlfile, query)¶ Compute the count for the XPath query.
- Parameters
xmlfile (str) – Name of input XML file.
query (str) – XPath 1.0 expression. This must evaluate to a node or node set.
- Returns
The integer value of
count(query).- Return type
int