Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据etree/python的父级,对同一个XML标记进行不同的处理?_Python_Xml_Elementtree - Fatal编程技术网

根据etree/python的父级,对同一个XML标记进行不同的处理?

根据etree/python的父级,对同一个XML标记进行不同的处理?,python,xml,elementtree,Python,Xml,Elementtree,我正在使用解析XML并从中创建python文件 在顶层,XML看起来像 <stage id="stage1"> <initialise> </initialise> <execute> </execute> </stage> 获取执行元素的Python如下所示: def parse_execute(self, elem): if elem[0].tag == 'required':

我正在使用解析XML并从中创建python文件

在顶层,XML看起来像

<stage id="stage1">
    <initialise>
    </initialise>
    <execute>
    </execute>
</stage>
获取执行元素的Python如下所示:

def parse_execute(self, elem):

    if elem[0].tag == 'required': #or elem[0].tag == 'variable':
        self.loop(elem)
    else:
        self.out('')
        self.out('def {0}():'.format(elem.tag))
        self.indent()
        self.loop(elem)
        self.dedent()

看到一个问题让人耳目一新,这个问题从我使用XML开始,然后实际开始显示有效的XML。我忘了包含一个指向完整XML示例的链接。哎呀。你想用这种方法解决什么问题?有一个系统同时运行在python和ASP上,它读取要运行的XML。有了这个,我试图让python端只读取python&从而加快进程。
def parse_execute(self, elem):

    if elem[0].tag == 'required': #or elem[0].tag == 'variable':
        self.loop(elem)
    else:
        self.out('')
        self.out('def {0}():'.format(elem.tag))
        self.indent()
        self.loop(elem)
        self.dedent()