当前位置: 首页>>代码示例>>Python>>正文


Python XML类代码示例

本文整理汇总了Python中XML的典型用法代码示例。如果您正苦于以下问题:Python XML类的具体用法?Python XML怎么用?Python XML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_countChildren_multipleChildren

	def test_countChildren_multipleChildren(self):
		s = "<xml><THU><Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly></Team><JiaJia><Team><Ahyangyi></Ahyangyi><Dragon></Dragon><Cooly><Amber></Amber></Cooly></Team></JiaJia></THU><Team><Cooly></Cooly><Jelly></Jelly></Team></xml>"
		a = fromstring(s)
		pattern = XML.getPattern(a)
		patternChildren = 0
		patternChildren = XML.countChildren(pattern)
		self.assertTrue(patternChildren == 2)
开发者ID:SnehaR,项目名称:xml-tests,代码行数:7,代码来源:jv23358-TestXML.py

示例2: main

def main():

    # part1:
    #-------------------------------------------------------------------
    Part1.Part1()
    #-------------------------------------------------------------------


    # part2:
    #-------------------------------------------------------------------
    # set last parameter to true to enable export of shots
    stitched_shots, all_shots, outstitched_shots = Part2.Part2(False)
    #-------------------------------------------------------------------


    #html stuff:
    #-------------------------------------------------------------------
    HTML.html_stuff(stitched_shots, all_shots, outstitched_shots, 'Oberstdorf16-shots.csv',
               './html_input/index_part1.txt', './html_input/index_part2.txt', './html_output/index.html')
    #-------------------------------------------------------------------


    #xml stuff:
    #-------------------------------------------------------------------
    XML.create_XML('caffe_output.txt')
开发者ID:zexe,项目名称:video_ret_proj1,代码行数:25,代码来源:Project1.py

示例3: dbIter

 def dbIter(self):
     if os.path.isfile(self.path):
         dom = XML.parseStream(open(self.path))
         for element in XML.getChildElements(dom.documentElement):
             if element.nodeName == "ruleset":
                 yield element
     else:
         log.msg("The file %r does not exist, loading no rulesets" % self.path)
开发者ID:Kays,项目名称:cia-vc,代码行数:8,代码来源:Ruleset.py

示例4: preprocess

    def preprocess(self):
        message = XML.dig(self.xml, "message")
        if not message:
            raise XML.XMLValidityError("A Message's root node must be named 'message'")

        # Stamp it with the current time if it has no timestamp yet
        if not XML.dig(message, "timestamp"):
            XML.addElement(message, "timestamp", "%d" % time.time())
开发者ID:SkyFire,项目名称:cia-vc,代码行数:8,代码来源:Message.py

示例5: test_count

	def test_count(self):
		s = "<xml><THU>\n\t<Team>\n\t\t<ACRush></ACRush>\n\t\t<Jelly></Jelly>\n\t\t<Cooly></Cooly>\n\t</Team>\n\t<JiaJia>\n\t\t<Team>\n\t\t\t<Ahyangyi></Ahyangyi>\n\t\t\t<Dragon></Dragon>\n\t\t\t<Cooly><Amber></Amber></Cooly>\n\t\t</Team>\n\t</JiaJia>\n</THU>\n<Team><Cooly></Cooly></Team>\n</xml>"
		a = fromstring(s)
		pattern = XML.getPattern(a)
		patternChildren = 0
		patternChildren = XML.countChildren(pattern)
		XML.numElements = 0
		XML.numElements = XML.count(a, pattern, patternChildren)
		self.assertTrue(XML.numElements == 13)
开发者ID:SnehaR,项目名称:xml-tests,代码行数:9,代码来源:jv23358-TestXML.py

示例6: test_count_breadth

	def test_count_breadth(self):
		s = "<xml><THU><Team></Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly><JiaJia></JiaJia><Ahyangyi></Ahyangyi><Dragon></Dragon></THU></xml>"
		a = fromstring(s)
		pattern = XML.getPattern(a)
		patternChildren = 0
		patternChildren = XML.countChildren(pattern)
		XML.numElements = 0
		XML.numElements = XML.count(a, pattern, patternChildren)
		self.assertTrue(XML.numElements == 8)
开发者ID:SnehaR,项目名称:xml-tests,代码行数:9,代码来源:jv23358-TestXML.py

示例7: test_findMatches

	def test_findMatches(self):
		s = "<xml><THU><Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly></Team><JiaJia><Team><Ahyangyi></Ahyangyi><Dragon></Dragon><Cooly><Amber></Amber></Cooly></Team></JiaJia></THU><Team><Cooly></Cooly></Team></xml>"
		a = fromstring(s)
		pattern = XML.getPattern(a)
		patternChildren = 0
		patternChildren = XML.countChildren(pattern)
		XML.locations = []
		XML.locations = XML.findMatches(a, pattern, patternChildren)
		self.assertTrue(XML.locations == []) #function only works in conjunction with the count function
开发者ID:SnehaR,项目名称:xml-tests,代码行数:9,代码来源:jv23358-TestXML.py

示例8: textComponent

 def textComponent(self, element, args, *path):
     """A convenience function for defining components that just look for a node
        in the message and return its shallowText.
        """
     element = XML.dig(args.message.xml, *path)
     if element:
         return [XML.shallowText(element)]
     else:
         return [MarkAsHidden()]
开发者ID:SkyFire,项目名称:cia-vc,代码行数:9,代码来源:Message.py

示例9: test_findMatches_guaranteed_match

	def test_findMatches_guaranteed_match(self):
		s = "<xml><THU><Team></Team></THU><THU></THU></xml>"
		a = fromstring(s)
		pattern = XML.getPattern(a)
		patternChildren = 0
		patternChildren = XML.countChildren(pattern)
		XML.matches = 0
		XML.findMatches(a, pattern, patternChildren)
		self.assertTrue(XML.matches == 0)
开发者ID:SnehaR,项目名称:xml-tests,代码行数:9,代码来源:jv23358-TestXML.py

示例10: getXMLMailHeaders

 def getXMLMailHeaders(self, document):
     """Return a <mailHeaders> tag representing a subset of the headers
        for this message. This is placed in the <generator> tag of any
        message passing through this module, to document and log the
        message's true source.
        """
     node = document.createElementNS(None, "mailHeaders")
     for name, value in self.message.items():
         if name in interestingHeaders:
             XML.addElement(node, "header", content=str(value)).setAttributeNS(None, 'name', name)
     return node
开发者ID:Kays,项目名称:cia-vc,代码行数:11,代码来源:IncomingMail.py

示例11: rulesetReturn

 def rulesetReturn(msg):
     nodes = xp.queryObject(msg)
     if nodes:
         self.result = XML.allText(nodes[0]).strip()
     else:
         self.result = None
     raise RulesetReturnException()
开发者ID:Kays,项目名称:cia-vc,代码行数:7,代码来源:Ruleset.py

示例12: element_like

 def element_like(self, element):
     """Compare a given variable to the element's content using SQL's 'LIKE' operator,
        not including leading and trailing whitespace. This is case-insensitive, and includes
        the '%' wildcard which may be placed at the beginning or end of the string.
        """
     return "(%s LIKE %s)" % (self.varLookup(element.getAttributeNS(None, 'var')),
                              quote(XML.shallowText(element).strip(), 'varchar'))
开发者ID:SkyFire,项目名称:cia-vc,代码行数:7,代码来源:Database.py

示例13: run_probes

    def run_probes(self):
        """ run probes and upload probe data """
        try:
            probes = XML.XML(str(self.proxy.GetProbes()))
        except (Proxy.ProxyError,
                Proxy.CertificateError,
                socket.gaierror,
                socket.error):
            err = sys.exc_info()[1]
            self.fatal_error("Failed to download probes from bcfg2: %s" % err)
        except XML.ParseError:
            err = sys.exc_info()[1]
            self.fatal_error("Server returned invalid probe requests: %s" %
                             err)

        self.times['probe_download'] = time.time()

        # execute probes
        probedata = XML.Element("ProbeData")
        for probe in probes.findall(".//probe"):
            probedata.append(self.run_probe(probe))

        if len(probes.findall(".//probe")) > 0:
            try:
                # upload probe responses
                self.proxy.RecvProbeData(
                    XML.tostring(probedata,
                                 xml_declaration=False).decode('utf-8'))
            except Proxy.ProxyError:
                err = sys.exc_info()[1]
                self.fatal_error("Failed to upload probe data: %s" % err)

        self.times['probe_upload'] = time.time()
开发者ID:dhutty,项目名称:bcfg2,代码行数:33,代码来源:__init__.py

示例14: matches

 def matches(self, msg):
     match = self.projectPath.queryObject(msg)
     if match:
         for node in match:
             project = XML.shallowText(node)
             if (project.strip().lower() in self.projects):
                 return True
     return False
开发者ID:Kays,项目名称:cia-vc,代码行数:8,代码来源:Ruleset.py

示例15: loadGames

def loadGames():
    try:
        f = open("./xml/packlist.chess", "r")
    except FileNotFoundError:
        return

    saves = f.readlines()

    for save in saves:
        save = save.rstrip()
        gameID = save[:save.find(":")]
        lastNum = save[save.find(":")+1:]

        g = Game()
        g.id = int(gameID)
        xmlPath = "./xml/"+gameID+"/"+lastNum+".xml"

        try:
            m = XML.parse_meta(xmlPath)
            g.password = m["password"]

            g.board.whoseTurn = WHITE if m["turn"] == "white" else BLACK
            g.board.xSize = int(m["sizeX"])
            g.board.ySize = int(m["sizeY"])
            g.movesmade = int(m["movesmade"])
            g.board.setup_fields()
        except KeyError:
            continue

        figures = XML.parse_figures(xmlPath)
        for figure in figures:
            g.board.getFieldByCords(figure.posx, figure.posy).figure = figure

        g.board.postMoveUpdate()

        if g.password is None:
            g.password = ""

        if g.movesmade > 3:
            glist.append(g)
            print("Loaded Game:", g.id)
        else:
            removeLine("./xml/packlist.chess", str(g.id)+":"+str(g.movesmade)+"\n")
            rmdir("./xml/"+str(g.id))
            print("Removed SaveGame:", g.id)
开发者ID:Idrias,项目名称:chess_game,代码行数:45,代码来源:file_operations.py


注:本文中的XML类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。