과 childNodes에에서 값을 검색하고 나는 childNodes에내가 XML에 아주 새로운 오전 minidom
에서 값을 검색하려는from xml.dom import minidom
def Get_ExtList(progName):
progFile='%s.xml'%progName
xmldoc = minidom.parse(progFile)
extList=[]
rootNode=xmldoc.firstChild
progNode=rootNode.childNodes[1]
for fileNodes in progNode.childNodes:
newList=[]
for formatNodes in fileNodes.childNodes:
for nodes in formatNodes.childNodes:
x=nodes.toxml()
x=' '.join(x.split())
newList.append(str(x))
extList.append(newList)
print extList
출력 :
[[], [‘.aaa'], [], [‘.bbb'], [], [‘.ccc'], [], [‘.ddd'], [], [‘.xxx', ‘.yyy'], []]
하지만
[[‘.aaa'], [‘.bbb'],[‘.ccc’],[‘.ddd'],[‘.xxx', ‘.yyy']]
를 다음과 같이 뭔가를 원하는
다음은 샘플 파일입니다.
<?xml version="1.0" ?>
<program>
<progname name="TEST">
<file>
<format>
.aaa
</format>
</file>
<file>
<format>
.bbb
</format>
</file>
<file>
<format>
.ccc
</format>
</file>
<file>
<format>
.ddd
</format>
</file>
<file>
<format>
.xxx
</format>
<format>
.yyy
</format>
</file>
</progname>
</program>
수정 코드를 실행할 수 있지만 트림 기능이 작동하지 않습니다. 다음과 같은 오류가 발생합니다. AttributeError : 'unicode'객체에 'trim'속성이 없습니다. 따라서 분할을 사용하여 작업을해야합니다. 위의 코드는 매우 깔끔하게 보이지만 작동 시키면 얻을 수 있습니다. 어떤 제안? – shash
@shabana '스트립'으로 '트림'을 혼동합니다. 지금 고쳐야한다. – phihag