0
我想將xml文件轉換爲csv文件,我嘗試了bash腳本awk,xmlstarlet但沒有運氣,現在我在python中嘗試這個但仍然沒有運氣,下面是我的示例 xml文件使用python將xml文件轉換爲csv文件
<items><item>
<Name>demo title 1</Name>
<FileType>image</FileType>
<ReleaseDate>15 May 2015</ReleaseDate>
<Quality>
HDRiP</Quality>
<size>2848292</size>
<Rating>6.6</Rating>
<Genre>Comedy,
Music</Genre>
<Cast>rules bank demo,
anademo demo 2,
Hai demo 3,
Ale Demo 4</Cast>
<Languages>English</Languages>
<Subtitles>
hindi</Subtitles>
<FileName>demo title 1 fname</FileName>
<FileSize>1.4GB</FileSize>
<NoOfFiles>5</NoOfFiles>
<UploadTime>4 months</UploadTime>
<DateOfDataCapture>May 29, 2015</DateOfDataCapture>
<TimesDownloaded>2,339</TimesDownloaded>
<UpVotes>+742</UpVotes>
<DownVotes>-37</DownVotes>
<MediaType>[1080p, 720p, Blu-Ray, BDRip, HDRiP, DVD, DVDRip, x264, WEB-DL, Cam]</MediaType>
<Summary>this is demo pics
collected for wallpapers only it is free available on many app and urls.
Written by
demo1.Cdemo324.78K
report summary</Summary>
</item><item>
<Name>demo title 2</Name>
<FileType>image</FileType>
<ReleaseDate>16 May 2015</ReleaseDate>
<Quality>
HDRiP</Quality>
<size>2855292</size>
<Rating>6.9</Rating>
<Genre>Comedy,
Music</Genre>
<Cast>rules bank demo,
anademo demo 12,
Hai demo 13,
Ale Demo 14</Cast>
<Languages>English</Languages>
<Subtitles>
hindi</Subtitles>
<FileName>demo title 2 fname</FileName>
<FileSize>1.3GB</FileSize>
<NoOfFiles>5</NoOfFiles>
<UploadTime>4 months</UploadTime>
<DateOfDataCapture>May 29, 2015</DateOfDataCapture>
<TimesDownloaded>2,339</TimesDownloaded>
<UpVotes>+742</UpVotes>
<DownVotes>-37</DownVotes>
<MediaType>[1080p, 720p, Blu-Ray, BDRip, HDRiP, DVD, DVDRip, x264, WEB-DL, Cam]</MediaType>
<Summary>this is demo pics 2
collected for wallpapers only it is free available on many app and urls.
Written by
demo2.C2demo324.78K
report summary</Summary>
</item>
</items>
i want convert into csv file and each <item> records should be in same line ,
when i am trying to use xml parser , it is converted records into csv file but issue is my tag values in multiple line and also contain new line character so it is converted csv in same way like
below is sample csv file converted.
demo title 1,image,15 May 2015,
HDRiP,
2848292,6.6,Comedy,
Music,rules bank demo,
anademo demo 2,
Hai demo 3,
Ale Demo 4,English
i want it new line character should be replace by space so all records of single items saved in one row in csv file .
我試圖蟒蛇XML解析器xml2csv太多,但梁沒有運氣,普萊舍建議我怎麼能讀取XML文件,並與空間刪除這些不必要的換行字符。
請看看[編輯的幫助(http://stackoverflow.com/editing-help)。 – Cyrus