コード例 #1
0
ファイル: my_xml_parser.py プロジェクト: ecotox/pacfm
    def set(self, item_tag, prop, value, refProp, refValue):
        for i in range(len(self.xmlBlocks)):
            # this step is done to avoid confusion due to the "<<" and ">>" signs
            in_text= self.xmlBlocks[i]
            root= ET.fromstring(in_text)
            #print root.text
             
            for item in root.iter():
                #print item.tag
                if item.tag == item_tag:
                    parser=SettingParser(item.text)
                    if refValue != "":
                        try:
                            if parser.get(refProp) == refValue:
                                parser.set(prop,value)
                        
                        except:
                            pass
                    
                    else:
                        parser.set(prop, value)
                    
                    item.text= parser.tostring()

            out_text = ET.tostring(root)
            self.xmlBlocks[i]= out_text
コード例 #2
0
ファイル: my_xml_parser.py プロジェクト: ecotox/pacfm
 def get(self, item_tag, prop="", child=None):
     for in_text in self.xmlBlocks:
         # this step is done to avoid confusion due to the "<<" and ">>" signs
         root= ET.fromstring(in_text)
         if root.tag == root_tag:
             ### we use XPath features of the xml.etree library here
             root.findall('.%s' % child)
             propSet= SettingParser(child.text)
             if propSet.get(refProp) == refValue:
                propSet.set(prop, value) 
                child.text= propText.tostring()