# This file is part of facho. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from lxml import etree from lxml.etree import Element, SubElement, tostring import re class LXMLBuilder: """ extrae la manipulacion de XML """ # TODO buscar el termino mas adecuado # ya que son varios lo procesos que se # exponen en la misma clase # * creacion # * busquedad # * comparacion def __init__(self, nsmap): self.nsmap = nsmap self._re_node_expr = re.compile(r'^(?P((?P\w+):)?(?P[a-zA-Z0-9_-]+))(?P\[.+\])?') self._re_attrs = re.compile(r'(\w+)\s*=\s*\"?(\w+)\"?') def match_expression(self, node_expr): match = re.search(self._re_node_expr, node_expr) return match.groupdict() @classmethod def from_string(cls, content, clean_namespaces=False): if clean_namespaces: content = re.sub(r'\<\s*[a-zA-Z\-0-9]+\s*:', '<', content) content = re.sub(r'\<\/\s*[a-zA-Z\-0-9]+\s*:', '