示例#1
0
文件: test.py 项目: hanshoi/MyMeego
def xmlTest():
    print "xml test set"
    print "create xml data"
    root = XmlData("root")
    child1 = XmlData("child1")
    child1.addAttribute(Attribute("name","gettomaster"))
    child1.addAttribute(Attribute("vip","34"))
    child11 = XmlData("child11")
    child1.addChild(child11)
    root.addChild(child1)
    child2 = XmlData("child2")
    root.addChild(child2)
    print "xml created"
    
    print "create file"
    xmlToFile(root,"data/asdad.xml")
    
    print "read xml from file"
    rootxml = fileToXml("data/asdad.xml")
    print "loaded root node: ",rootxml.name
        
    print "Test get child & attribute functions"
    c1 = rootxml.getChild("child1")
    c1.getAttribute("name")
    try:
        rootxml.getChild("xxx")
        rootxml.getAttribute("yyy")
    except:
        pass
    else:
        print "ERROR: no exception raised."
        
    print "compare results"
    _compareXmlData(root,rootxml)
    print "results compared"
示例#2
0
 def load(self,filename):
     data = fileToXml(filename)
     
     if data.name != "config":
         print "ERROR: file was not a config file"
         return
     
     try:
         for child in data.getChildren():
             if child.name == "device":
                 self.device_type = child.getAttribute("type").value
                 print "DeviceType:",self.device_type
             if child.name == "name":
                 self.device_name = child.getAttribute("value").value
                 print "DeviceName:",self.device_name
             if child.name == "temp_folder":
                 self.temp_folder = child.getAttribute("path").value
                 print "TempFolder:",self.temp_folder
             if child.name == "coherence_config":
                 self.coherence_conf = child.getAttribute("path").value
                 print "CoherenceConfig:",self.coherence_conf      
             if child.name == "fake_actions":
                 val = child.getAttribute("use_fake").value
                 if val == "true":
                     self.fake_actions = True
                 else:
                     self.fake_actions = False             
             if child.name == "folders":
                 for folder in child.getChildren():
                     if folder.name == "folder":
                         path = folder.getAttribute("path").value
                         self.share_folders.append(path)
                         print "SharePath:",path
     except AttributeError as e:
         print "Does not find config attribute",e.value
         
         
     self._is_loaded = True