dongxian5735 2013-09-25 22:32
浏览 64
已采纳

php从xml中删除额外的括号

I need to parse a huge xml of photo albums. I'm using PHP SimpleXML to parse, however it fails on some entries with errors because extra brackets may appear in some cases, see 'description' or 'CameraModel' tags.

How do I clean up xml before loading it with SimpleXML? If possible, replace extra brackets with '_' underscore.

Here is my 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>
  • 写回答

1条回答 默认 最新

  • douqiangchuai7674 2013-09-25 23:01
    关注

    Use regex

    print preg_replace("/(<([\w]+)[^>]*>.*)(<)(.*<\/\\2>)/", "$1_$4", $xml);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗