zoukankan      html  css  js  c++  java
  • xmltodict 同级目录下 两个相同node 去除

    a="<div id='div1'><a id='a1'>1</a><a id='a2'></a></div>"

    b=xmltodict.parse(a)  

       b=OrderedDict([('div', OrderedDict([('@id', 'div1'), ('a', [OrderedDict([('@id', 'a1'), ('#text', '1')]), OrderedDict([('@id', 'a2')])])]))])

    c="<a id='a1'>1</a>"

    d=xmltodict.parse(c)  = OrderedDict([('a', OrderedDict([('@id', 'a1'), ('#text', '1')]))])

    b['div']['a']=[OrderedDict([('@id', 'a1'), ('#text', '1')]), OrderedDict([('@id', 'a2')])]   #列表

    b['div']['a'].remove(d['a'])  #     OrderedDict([('div', OrderedDict([('@id', 'div1'), ('a', [OrderedDict([('@id', 'a2')])])]))])

    xmltodict.unparse(b)  # '<?xml version="1.0" encoding="utf-8"?> <div id="div1"><a id="a2"></a></div>'

  • 相关阅读:
    UVA 10608 Friends
    UVA 10806 Dijkstra, Dijkstra.
    HDU 3715 Go Deeper
    poj1315
    poj1383
    poj1650
    poj1265
    poj1523
    RedHat9.0虚拟机安装
    注册DirectShow filter时应该注意中文路径
  • 原文地址:https://www.cnblogs.com/a10086/p/10023832.html