我需要解析一個巨大的xml相冊。我使用PHP SimpleXML進行分析,但是它在某些錯誤條目上失敗,因爲在某些情況下可能會出現額外的括號,請參閱'description'或'CameraModel'標籤。php從xml中刪除多餘的括號
如何在使用SimpleXML加載之前清理xml?如果可能,用'_'下劃線替換額外的括號。
這裏是我的xml:
<values>
<photos>
<photo><photoID>4521</photoID>
<name></name>
<description>Seattle<3</description>
<fileName>S5001497.jpg</fileName>
<fileSize>177513</fileSize>
<fileSizeOriginal>2359669</fileSizeOriginal>
<width>1200</width>
<height>900</height>
<exif><CameraModel><Digimax S500/Kenox S500</CameraModel>
<CameraMake>Samsung Techwin</CameraMake>
<DateTime>2008-07-12 17:37:24</DateTime>
<Version>220</Version>
<SourceWidth>2592</SourceWidth>
<SourceHeight>1944</SourceHeight>
<Orientation>1</Orientation>
<FlashUsed>89</FlashUsed>
<FocalLength>5.8</FocalLength>
<ExposureTime>0.033333</ExposureTime>
<Brightness></Brightness>
<ApertureFNumber>2.8</ApertureFNumber>
<ISO>177</ISO>
<ExposureProgram>0</ExposureProgram>
</exif>
<type>photo</type>
<GPS></GPS>
</photo>
</photos>
</values>
你有過XML文件控制?摘錄括號不是有效的XML,應該輸入爲'<' – Robbert
就任何解析器而言,這不是XML。這個問題應該通過在源頭使用實體引用('<')來解決。 –
我無法控制XML,它是由信譽良好的網站生成的,它們不會更改xml。 – Vital