我正在编写一个从Flickr API下载数据的iPhone应用程序。目前似乎没有办法限制它下载了多少comments,虽然我想得到8或10,但它有时会发给我数百。我有subclassed ASIHTTPRequest,因此它只会下载一定数量的字节(例如,它会在收到1024字节的评论数据后停止下载)。
现在,我要解析的信息就在那里(评论数据包含用户ID,文本等内容)。但是,由于它在结束之前被切断,因此XML格式错误,而我当前的解决方案(使用ObjectiveFlickr的XML解析器)无法解析XML。有没有办法处理格式错误的XML,就像旧的Web浏览器处理HTML一样,只提取结构良好的数据?
以下是一些示例数据:
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<comments photo_id="5692627867">
<comment id="49862655-5692627867-72157626659891768" author="29114051@N05" authorname="eαse*" iconserver="4046" iconfarm="5" datecreate="1304689286" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626659891768">lovely lovely lovelyyyyy!!! ♥♥♥♥♥♥♥♥♥</comment>
<comment id="49862655-5692627867-72157626535581359" author="49946698@N06" authorname="RandomPics Art" iconserver="4017" iconfarm="5" datecreate="1304692593" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626535581359">nice! like soft colors and tones!</comment>
<comment id="49862655-5692627867-72157626660240896" author="49907977@N06" authorname="kiki_chi" iconserver="4014" iconfarm="5" datecreate="1304693051" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626660240896">&gt;eαse*
&gt;RandomPics Art
Thank you:) :) :)</comment>
<comment id="49862655-5692627867-72157626660761230" author="41717031@N08" authorname="petia.bourova" iconserver="4082" iconfarm="5" datecreate="1304698244" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626660761230">Thank you!Very nice photo!I like The coulers very,very much!!!</comment>
<comment id="49862655-5692627867-72157626661258700" author="31540474@N08" authorname="Leentje32" iconserver="4067" iconfarm="5" datecreate="1304703576" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626661258700">Aww so lovely!! Beautiful capture.</comment>
<comment id="49862655-5692627867-72157626662413410" author="61373986@N06" authorname="My NIKON And Me" iconserver="5310" iconfarm="6" datecreate="1304716098" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626662413410">lovely image!!!</comment>
<comment id="49862655-5692627867-72157626663408864" author="7652657@N02" authorname="Majlee" iconserver="3130" iconfarm="4" datecreate="1304728344" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663408864">This is just adorable !</comment>
<comment id="49862655-5692627867-72157626663519092" author="15613254@N05" authorname="mr_jyoti" iconserver="4011" iconfarm="5" datecreate="1304729940" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663519092">Cool shot. Nice bokey.</comment>
<comment id="49862655-5692627867-72157626663642456" author="16327396@N03" authorname="my beanie hat rocks" iconserver="2550" iconfarm="3" datecreate="1304731810" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663642456">Maybe she could cheer this fella up!!
<a href="http://www.flickr.com/photos/weasteman/5652855802/in/photostream">www.flickr.com/photos/weasteman/5652855802/in/photostream</a>
=D</comment>
答案 0 :(得分:1)
我不确定确切的XML格式,但看起来很简单。在这种情况下,您可以尝试找出数据中的最后一个标记,并手动添加缺少的结束标记。它不应该只是一个简单的字符串搜索&amp;取代