首页 新闻 会员 周边

python读取xml文档,能够正确显示标签,但是对应的value为None

0
悬赏园豆:10 [待解决问题]

python code:

#!/usr/bin/python
from xml.dom.minidom import parse,parseString
dom = parse("/home/lxl/interface/requestBody/CreateObjS3.xml")
properties = dom.firstChild
ts_node = properties.childNodes
lstList = []
for sw in ts_node:
    if sw.nodeType == sw.ELEMENT_NODE:
        swName=sw.nodeName
        swValue=sw.nodeValue
        v=(swName,swValue)
        lsty=[]
        lsty.append(v)
        for nd in sw.childNodes:
            if nd.nodeType == nd.ELEMENT_NODE:
                ndName = nd.nodeName
                ndValue = nd.nodeValue
                b = (ndName,ndValue)
                lsty.append(b)
        lstList.append(lsty)
print lstList[0:]

xml:

<?xml version="1.0"?>
<properties>
  <method>put</method>
  <host></host>
  <bucketName></bucketName>
  <secret></secret>
  <parameter>
    <CodeId></CodeId>
  </parameter>
  <head>
    <Authorization></Authorization>
    <x-amz-acl></x-amz-acl>
    <Content-MD5></Content-MD5>
    <x-amz-meta-a></x-amz-meta-a>
    <x-amz-meta-length></x-amz-meta-length>
    <x-amz-meta-meta1></x-amz-meta-meta1>  
</head>
</properties>

我需要输出Method的value值put,但是结果始终显示为None,求高手指点。

 


   

毛毛细雨的主页 毛毛细雨 | 初学一级 | 园豆:185
提问于:2013-07-09 22:19
< >
分享
所有回答(2)
0
dudu | 园豆:30994 (高人七级) | 2013-07-10 08:59
0
from xml.dom.minidom import parse,parseString
dom = parse("CreateObjS3.xml")
properties = dom.firstChild
ts_node = properties.childNodes
lstList = []
for sw in ts_node:
    if sw.nodeType == sw.ELEMENT_NODE:
        swName=sw.nodeName
        swValue=sw.childNodes[0].nodeValue
        v=(swName,swValue)
        lsty=[]
        lsty.append(v)
        for nd in sw.childNodes:
            if nd.nodeType == nd.ELEMENT_NODE:
                ndName = nd.nodeName
                ndValue = nd.childNodes[0].nodeValue
                b = (ndName,ndValue)
                lsty.append(b)
        lstList.append(lsty)
print lstList[0:]
Fran.Austin | 园豆:202 (菜鸟二级) | 2013-10-31 23:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册