se adiciona FachoXml.get_element_text_or_attribute

FossilOrigin-Name: 2179f4376613dda1e554a4f1304990f32185c1ec9bec6181d8a00e31a5ee5390
This commit is contained in:
bit4bit
2021-11-06 20:43:07 +00:00
parent 35e1c5b609
commit 8d17c282e3
4 changed files with 45 additions and 16 deletions

View File

@@ -368,6 +368,16 @@ class FachoXML:
text = self.builder.get_text(elem)
return format_(text)
def get_element_text_or_attribute(self, xpath):
parts = xpath.split('/')
is_attribute = parts[-1].startswith('@')
if is_attribute:
attribute_name = parts.pop(-1).lstrip('@')
element_path = "/".join(parts)
return self.get_element_attribute(element_path, attribute_name)
else:
return self.get_element_text(xpath)
def exist_element(self, xpath):
elem = self.get_element(xpath)