亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2557 | 回復(fù): 3
打印 上一主題 下一主題

xml相關(guān)問題 [復(fù)制鏈接]

論壇徽章:
1
申猴
日期:2014-03-27 09:12:41
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-03-04 15:58 |只看該作者 |倒序瀏覽
import xml.etree.ElementTree as ET
country_data_as_string="""<?xml version="1.0"?>
<data>
    <country name="Liechtenstein">
        <rank>1</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank>4</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank>68</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
"""
tree = ET.parse('country_data.xml')
root = tree.getroot()
root = ET.fromstring(country_data_as_string)

      
tree=ET.ElementTree(root)

對于這個程序,我想修改其中的一個rank值或者是任意改變這三個rank值,該怎么弄?我試了下find()但是好像不行還是我寫的不對。求大神指點下

論壇徽章:
11
技術(shù)圖書徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
2 [報告]
發(fā)表于 2014-03-04 17:35 |只看該作者
回復(fù) 1# 鑄劍長空
還沒搞定?文檔的“XPath support”,有幾個例子。下面是找第二個rank,兩種方法,找到后應(yīng)該會修改吧。
  1. >>> root.find('./country[2]/rank').text
  2. '4'
  3. >>> root.find("./country[@name='Singapore']/rank").text
  4. '4'
復(fù)制代碼

論壇徽章:
1
申猴
日期:2014-03-27 09:12:41
3 [報告]
發(fā)表于 2014-03-05 17:34 |只看該作者
跪謝。。當(dāng)時用的時候沒搞懂。。試了好多次不成。。多謝多謝。。回復(fù) 2# timespace


   

論壇徽章:
1
申猴
日期:2014-03-27 09:12:41
4 [報告]
發(fā)表于 2014-03-08 13:53 |只看該作者
你好,還有個問題想問下,我要用的xml的文件有很多層,比如


我想讀出Aera的值
import xml.etree.ElementTree as ET
with open('jiyi.xml') as fp:
    jiyi_as_string=fp.read()
tree = ET.parse('jiyi.xml')
root = tree.getroot()
root = ET.fromstring(jiyi_as_string)
x1=root.find('./Vsp_Geometry/Component_List[1]/Component/Section_List/Section/Area').text
print x1
這是我寫的程序
但是出現(xiàn)了
Traceback (most recent call last):
  File "F:\python練習(xí)\jiexi", line 4, in <module>
    tree = ET.parse('jiyi.xml')
  File "H:\Python27\lib\xml\etree\ElementTree.py", line 1182, in parse
    tree.parse(source, parser)
  File "H:\Python27\lib\xml\etree\ElementTree.py", line 656, in parse
    parser.feed(data)
  File "H:\Python27\lib\xml\etree\ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "H:\Python27\lib\xml\etree\ElementTree.py", line 1506, in _raiseerror
    raise err
ParseError: mismatched tag: line 243, column 39
這樣的錯誤,不知道怎么修改。。

回復(fù) 2# timespace
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP