xmlclass/xmlclass.py
changeset 1300 8e1ee07bdff8
parent 1294 f02ba5b83811
child 1303 908a5803c2cc
equal deleted inserted replaced
1299:9ffc49bfdf9d 1300:8e1ee07bdff8
  2007 
  2007 
  2008 """
  2008 """
  2009 This function generate a xml parser from a class factory
  2009 This function generate a xml parser from a class factory
  2010 """
  2010 """
  2011 
  2011 
       
  2012 NAMESPACE_PATTERN = re.compile("xmlns(?:\:[^\=]*)?=\"[^\"]*\" ")
       
  2013 
  2012 class DefaultElementClass(etree.ElementBase):
  2014 class DefaultElementClass(etree.ElementBase):
  2013     
  2015     
  2014     def init(self):
  2016     def init(self):
  2015         pass
  2017         pass
  2016     
  2018     
  2017     def getLocalTag(self):
  2019     def getLocalTag(self):
  2018         return etree.QName(self.tag).localname
  2020         return etree.QName(self.tag).localname
  2019         
  2021         
  2020     def tostring(self):
  2022     def tostring(self):
  2021         return etree.tostring(self, pretty_print=True)
  2023         return NAMESPACE_PATTERN.sub("", etree.tostring(self, pretty_print=True))
  2022 
  2024 
  2023 class XMLElementClassLookUp(etree.PythonElementClassLookup):
  2025 class XMLElementClassLookUp(etree.PythonElementClassLookup):
  2024     
  2026     
  2025     def __init__(self, classes, *args, **kwargs):
  2027     def __init__(self, classes, *args, **kwargs):
  2026         etree.PythonElementClassLookup.__init__(self, *args, **kwargs)
  2028         etree.PythonElementClassLookup.__init__(self, *args, **kwargs)