phpmyadmin을 사용하여 mysql 데이터베이스를 xml로 내 보낸 다음 minidom과 구문 분석하고 싶지만 필요한 형식으로 내용을 가져 오는 데 문제가 있습니다. .Mysql에서 데이터 추출 xml.dom.minidom을 사용하여 XML 덤프
요약 : 나는 추출 된 DB는 다음과 같습니다 <column name="news_title">This is the title</column>
에 포함 된 텍스트 변수 title
을 할당해야합니다
<pma_xml_export version="1.0" >
<database name="dbname">
<!-- Table newsbox -->
<table name="newsbox">
<column name="news_id">1</column>
<column name="news_title">This is the title</column>
<column name="news_text">This is the news text</column>
<column name="date">Thu, 28 Feb 2008 20:10:30 -0500</column>
<column name="author">author</column>
<column name="category">site_announcement</column>
</table>
</database>
</pma_xml_export>
나는 다음과 같은 스크립트를 사용하여 텍스트를 추출 할 수 있어요하지만 그건 내가 필요로하는 형태가 아닙니다 :
doc = parseString(document)
pmaexport = doc.getElementsByTagName("pma_xml_export")[0]
columns = pmaexport.getElementsByTagName("column")
for item in columns:
name = item.getAttribute("name")
text = item.firstChild.data.strip()
print name, text
내가 필요한 것은 텍스트를 할당 할 수있는 부분입니다. 예를 들어 전달 될 수있는 변수에 이러한 요소의 TS, DB를 출력 <title>Here's the Title</title>
의 형태 나 떨어져 가고 예제를 많이 할 것이다 있었다, 그러나 나는 단지에 대한 참조를 찾을 수없는 경우
for item in columns:
title = ???
text = ???
date = ???
author = ???
내가 xml.dom.minidom
을 사용했지만이 일을해야하기 때문에 <column name="news_title">This is the title</column>