Skip to main content

Data

Library to execute XPATH-queries to the XML-datafile of a rendering.

Introduction​

This library is used by the data_provider-library to execute the actual queries to the XML-datafile as XPATH-queries. It is recommended to use the buckets- or data-provider-libraries for querying and leaving this library as a middleware for the queries. Nonetheless, the most important querying-methods are explained here.

Class​

DataQueries(...)​

( datafile = "" )​

After importing the library, an instance of the DataQueries-class can be initialized. Should it be necessary, a custom datafile can be specified. By default, the file products.xml is used as datafile, as configured in the DATAFILE-attribute of the configuration-file renderpdf/comet/datafiles.xml. Whenever a new datafile is given, its resulting ElemetTree-object is cached until a different datafile is given upon object-initialization.

Parameters:_datafile (str)
(Optional) A path to an XML-file.
Returns:An instance of DataQueries
Return Type:DataQueries

Methods​

query_value(...)​

( query_string )​

Parameters:query_string (str)
The XPATH-query to be executed.
Returns:A string of the value found in the XML-datafile or an empty string.
Return Type:str

query_list(...)​

( query_string )​

Parameters:query_string (str)
The XPATH-query to be executed.
Returns:A list of strings with the values found in the XML-datafile or an empty list.
Return Type:list

query_keyvalues_pairs(...)​

( query_string, attribute_keys=None )​

Parameters:query_string (str)
The XPATH-query to be executed.
attribute_keys (dict[str,str])
Replace attributes in xml-queries with custom attributes. By default,
Returns:A dictionary with the found key-values or an empty dictionary.
Return Type:dict[str,str]

query_keyvalues_list(...)​

( query_string, attribute_keys=None )​

Parameters:query_string (str)
The XPATH-query to be executed.
attribute_keys (dict[str,str])
Replace attributes in xml-queries with custom attributes. By default,
Returns:A list of dictionaries with the found key-values per found element or an empty list.
Return Type:list[dict[str,str]]