xml_common package#
Util functionalities used across all library.
XMLObject Abstract Base Class#
- class xml_common.xml_object.XMLObject#
Bases:
ABCAbstract class for XML Object, to be parsed on the read of the Darwin Core Archive file.
- Attributes:
- NAMESPACE_TAG
Methods
check_principal_tag(tag, nmap)Checks if the tag is the Principal tag of the object.
from_string(text)Generates XML Object from a string of an XML file.
from_xml(file[, encoding])Generates an XML Object from an XML file.
Returns the principal tag with namespaces if it is present.
object_to_element(tag[, prefix])Generates an element using tag, adding namespace tag.
parse(element, nmap)Parses a lxml element into an XMLObject.
Generates a lxml.tree.Element from the object.
to_xml()Generates text of an XML file.
- NAMESPACES = {'xml': 'http://www.w3.org/XML/1998/namespace'}#
Dict[str, str] : Namespaces to use on the particular XML portion that represent the object.
- NAMESPACE_TAG = None#
str : If the principal tag has a namespace attribute, this must be used.
- PRINCIPAL_TAG = 'placeholder'#
str : The principal tag of the XML document.
- classmethod check_principal_tag(tag: str, nmap: Dict) None#
Checks if the tag is the Principal tag of the object.
- Parameters:
- tagstr
Tag obtained from outside source.
- nmapDict
The namespace to check the format of the Principal tag.
- Raises:
- AssertionError
If the tag is not a representation of the principal tag of the object.
- classmethod from_string(text: str) XMLObject#
Generates XML Object from a string of an XML file.
- Parameters:
- textstr
XML File as a string.
- Returns:
- XMLObject
Object parsed from the string.
- classmethod from_xml(file: str, encoding: str = 'utf-8') XMLObject#
Generates an XML Object from an XML file.
- Parameters:
- filestr
Path to XML file.
- encodingstr, default “utf-8”
Encoding of the XML file.
- Returns:
- XMLObject
Parsed XML object from XML file.
- get_principal_tag() str#
Returns the principal tag with namespaces if it is present.
- Returns:
- str
Principal tag of the XML file.
- object_to_element(tag: str, prefix: str | None = None) Element#
Generates an element using tag, adding namespace tag.
- Parameters:
- tagstr
Tag for XML Element.
- prefixstr, optional
Prefix of namespace, default None.
- Returns:
- lxml.tree.Element
Generated element.
- abstract classmethod parse(element: Element, nmap: Dict) XMLObject | None#
Parses a lxml element into an XMLObject.
- Parameters:
- elementlxml.tree.Element
Object in the Element format to be parsed into a Python object.
- nmapDict
Dictionary of namespace.
- Returns:
- XMLObject
Object parsed.
- abstract to_element() Element#
Generates a lxml.tree.Element from the object.
- Returns:
- lxml.tree.Element
Object in the Element format.
- to_xml() str#
Generates text of an XML file.
- Returns:
- str
Text of an XML File from the object.
Utils Module#
- xml_common.utils package
- CamelCase Enum
- Language Class
- Defined Values
LengthUnitLengthUnit.ANGSTROMLengthUnit.CENTIMETERLengthUnit.DECIMETERLengthUnit.DEKAMETERLengthUnit.FATHOMLengthUnit.FOOTLengthUnit.FOOT_GOLD_COASTLengthUnit.FOOT_USLengthUnit.HECTOMETERLengthUnit.INCHLengthUnit.KILOMETERLengthUnit.LINK_CLARKELengthUnit.MEGAMETERLengthUnit.METERLengthUnit.MICROMETERLengthUnit.MICRONLengthUnit.MILELengthUnit.MILLIMETERLengthUnit.NANOMETERLengthUnit.NAUTICALMILELengthUnit.YARDLengthUnit.YARD_INDIANLengthUnit.YARD_SEARSLengthUnit.valid_name
EstablishmentMeans
- Type Function
- Iteration
- GPolygon