我有一個具有巨大數據大小的XML文件。使用SAX將XML轉換爲CSV Python
XML文件包含
<us-bibliographic-data-grant>
<publication-reference>
<document-id>
<country>US</country>
<doc-number>D0607176</doc-number>
<kind>S1</kind>
<date>20100105</date>
</document-id>
</publication-reference>
<application-reference appl-type="design">
<document-id>
<country>US</country>
<doc-number>29327507</doc-number>
<date>20081107</date>
</document-id>
</application-reference>
<invention-title id="d0e55">Doughnut product with six appendages</invention-title>
<applicants>
<applicant sequence="001" app-type="applicant-inventor" designation="us-only">
<addressbook>
<last-name>Peters</last-name>
<first-name>Brian Jeffery</first-name>
<address>
<street>7052 Moonlight Cir.</street>
<city>Huntington Beach</city>
<state>CA</state>
<postcode>92647</postcode>
<country>US</country>
</address>
</addressbook>
<nationality>
<country>omitted</country>
</nationality>
<residence>
<country>US</country>
</residence>
</applicant>
</applicants>
</us-bibliographic-data-grant>
我怎樣才能得到這樣
last-name,first-name,street,city,state,postcode,country
peters,brian jeffery, 7052 moonlight cir.,huntington beach,CA,92647
我沒有任何經驗可言的XML輸出,請幫忙 在這個XML代碼中,有很多<addressbook>
。那麼如何獲得第一行中的applicant
內的所有屬性,並且下一行由所有值填充。我想這樣做,因爲我想稍後將csv文件導入到sql。
此xml無效。 – dawg 2013-04-06 18:01:15
爲什麼?我只是複製了它的一部分,很多有一些startElements沒有結束元素 – 2013-04-07 01:53:34
粘貼XML [HERE](http://www.xmlvalidation.com)或其他一些驗證器。嘗試通過解析器運行它。它無效或完全形成。 – dawg 2013-04-07 05:32:51