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,求高手指点。
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:]