Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
Python elementtree,编辑元素列表列表_Python_Xml_List_Elementtree - Fatal编程技术网

Python elementtree,编辑元素列表列表

Python elementtree,编辑元素列表列表,python,xml,list,elementtree,Python,Xml,List,Elementtree,我有一个相关元素列表,下面是一个片段。因此,config和action是命令的子项: all1= [[<Element '{http://clish.sourceforge.net/XMLSchema}COMMAND' at 0x7ff2ae48b690>, <Element '{http://clish.sourceforge.net/XMLSchema}PARAM' at 0x7ff2ae48b710>, <Element '{http://clish.sour

我有一个相关元素列表,下面是一个片段。因此,
config
action
命令的子项

all1= [[<Element '{http://clish.sourceforge.net/XMLSchema}COMMAND' at 0x7ff2ae48b690>, <Element '{http://clish.sourceforge.net/XMLSchema}PARAM' at 0x7ff2ae48b710>, <Element '{http://clish.sourceforge.net/XMLSchema}ACTION' at 
0x7ff2ae48b750>, <Element '{http://clish.sourceforge.net/XMLSchema}CONFIG' at 
0x7ff2ae48b790>], [<Element '{http://clish.sourceforge.net/XMLSchema}COMMAND' at
0x7ff2ae48b890>, <Element '{http://clish.sourceforge.net/XMLSchema}CONFIG' at 
0x7ff2ae48b8d0>, <Element '{http://clish.sourceforge.net/XMLSchema}ACTION' at 
0x7ff2ae48b950>], [<Element '{http://clish.sourceforge.net/XMLSchema}COMMAND' at 
0x7ff2ae48ba10>, <Element '{http://clish.sourceforge.net/XMLSchema}CONFIG' at 
0x7ff2ae48ba50>, <Element '{http://clish.sourceforge.net/XMLSchema}ACTION' at 
0x7ff2ae48bad0>], [<Element '{http://clish.sourceforge.net/XMLSchema}COMMAND' at 
0x7ff2ae48bb90>, <Element '{http://clish.sourceforge.net/XMLSchema}CONFIG' at 
0x7ff2ae48bbd0>, <Element       '{http://clish.sourceforge.net/XMLSchema}ACTION' at 
0x7ff2ae48bc50>]]
我希望将每个action元素的文本更改为每个config标记的属性

以下是我的意思的一个例子:

<COMMAND name="shutdown"
        help="Shutdown the selected interface">
        <CONFIG priority="0x7F01" />
        <ACTION>
        /klas/klish-scripts/interfaces.py conf -i ${iface} --enable 0
        </ACTION>
    </COMMAND>

    <COMMAND name="no shutdown"
        help="Enable the selected interface">
        <CONFIG operation="unset" pattern="^shutdown"/>
        <ACTION>
        /klas/klish-scripts/interfaces.py conf -i ${iface} --enable 1
        </ACTION>
    </COMMAND>

/klas/klish scripts/interfaces.py conf-i${iface}——启用0
/klas/klish scripts/interfaces.py conf-i${iface}——启用1
第一个配置有一个属性,因此它的操作标记文本应更改为“0x7F01” 在第二个配置中有“unset”和“shutdown”,因此这应该是新的操作文本,将其保留为新的xml:

<COMMAND name="shutdown"
        help="Shutdown the selected interface">
        <CONFIG priority="0x7F01" />
        <ACTION>
        0x7F01
        </ACTION>
    </COMMAND>

    <COMMAND name="no shutdown"
        help="Enable the selected interface">
        <CONFIG operation="unset" pattern="^shutdown"/>
        <ACTION>
        unset ^shutdown
        </ACTION>
    </COMMAND>

0x7F01
取消设置^shutdown
所以我应该将每个attrib设置为一个变量,并将其传递给action.text

如果我在创建列表之前完成了这些操作,这会更容易吗?通过操纵元素然后添加它们?我已经参考了标签、文本等。或者我仍然可以用元素列表来完成这项工作

<COMMAND name="shutdown"
        help="Shutdown the selected interface">
        <CONFIG priority="0x7F01" />
        <ACTION>
        0x7F01
        </ACTION>
    </COMMAND>

    <COMMAND name="no shutdown"
        help="Enable the selected interface">
        <CONFIG operation="unset" pattern="^shutdown"/>
        <ACTION>
        unset ^shutdown
        </ACTION>
    </COMMAND>