Skip to content
Snippets Groups Projects

XML Converter

Merged Alexander Schlemmer requested to merge f-xml-converter into dev
All threads resolved!
3 files
+ 79
7
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -24,6 +24,7 @@
#
import warnings
import lxml.etree
class StructureElement(object):
@@ -167,3 +168,53 @@ class DictDictElement(DictElement):
def __init__(self, *args, **kwargs):
warnings.warn(DeprecationWarning("This class is depricated. Please use DictElement."))
super().__init__(*args, **kwargs)
class XMLTagElement(StructureElement):
"""
Stores elements of an XML tree.
"""
def __init__(self, element: lxml.etree.Element):
super().__init__(element.getroottree().getelementpath(element))
self.tag = element
class XMLTextNode(StructureElement):
"""
Stores text nodes of XML trees.
"""
def __init__(self, element: lxml.etree.Element):
"""
Initializes this XML text node.
Please note that, although syntactically similar, it is semantically
different from TextElement:
- TextElements have a meaningful name, e.g. a key in a key-value pair. This name can
be matched using the match_name entry.
- XMLTextNodes just have a text and the name is just for identifying the structure element.
They can only be matched using the match entry in the XMLTextNodeConverter.
"""
super().__init__(element.getroottree().getelementpath(element) + "/text()")
self.tag = element
self.value = element.text
class XMLAttributeNode(StructureElement):
"""
Stores text nodes of XML trees.
"""
def __init__(self, element: lxml.etree.Element,
key: str):
"""
Initializes this XML attribute node.
element: The xml tree element containing the attribute.
key: The key which identifies the attribute in the list of attributes.
"""
super().__init__(element.getroottree().getelementpath(element) + "@" + key)
self.value = element.attrib[key]
self.key = key
self.tag = element
Loading