0
xml이 파이썬으로 출력되는 데 문제가 있습니다. 올바른 노드를 읽는 방법을 확신 할 수 없습니다. 내가 현재하고있는 것을 실행하면 아무것도 인쇄되지 않습니다. 오류가없고 인쇄 만합니다.파이썬에서 xml 노드 인쇄하기
XML 스크립트
<NEWS>
<ARTICLE>
<TITLE>Mark Mulder ends 2015 comeback bid</TITLE>
<AUTHOR>Igor</AUTHOR>
<PUBLIC>T</PUBLIC>
<CONTENT>
38-year-old left-hander Mark Mulder will not be attempting another comeback this tear, according to Jerry Crasnick of ESPN and Baseball America. Mulder tried to return from a lengthy hiatus last year, but a comeback bid ended with a spring training injury in Angels camp last year. "I just couldn't get where I needed to be," Mulder said. Mulder went 103-60 with a 4.18 ERA in nine years in the majors. He hasn't pitched in an MLB game since 2008.
</CONTENT>
</ARTICLE>
<NEWS>
파이썬 코드 : 모든 코드에서 별도의 탭이 왜
import xml.dom.minidom as minidom
document = minidom.parse("cgi-bin/news.xml")
page = document.childNodes[0]
print "<html>"
print "<head><title>NEW News Articles List</title></head>"
print "<body>"
print "<h2>Welcome to New News Inc.!<br> You are currently a GUEST here.</h2>"
print """\
<form method="GET" >
<input type="submit" value="Submit" name="loginPageCall" >
</form>
"""
for child in page.childNodes:
if child.nodeType == minidom.Node.TEXT_NODE:
sys.stdout.write(child.data)
elif child.nodeType == minidom.Node.ELEMENT_NODE:
if child.nodeName == "TITLE":
sys.stdout.write('<a href="%s">%s</a>' % (child.getAttribute("url"), child.childNodes[0].data))