可能使用NSScanner来分隔数据

时间:2014-04-09 12:41:02

标签: xml url jpeg nsscanner

我正在解析一些XML数据,其中一个元素包含多个URLs,这些JPG由逗号分隔,指向URL个文件。我如何将每个NSScanner与字符串分开并将其分配给变量以便我可以拉出单个图片?我在想URLs会起作用,因为它扫描字符串寻找某些字符,但我并不完全确定。我还读到正则表达式也是可能的。关于我应该从哪里开始的想法?还有其他人需要将XML与字符串分开吗?此外,这是一个<vehicle> <stock>T107810A</stock> <year>2009</year> <make>Porsche</make> <model>Cayenne</model> <trim>4WD</trim> <color>Black</color> <serial>WP1AD29PX9LA64805</serial> <miles>38907</miles> <cost>0</cost> <internet>46241</internet> <images>http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_1.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_2.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_3.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_4.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_5.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_6.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_7.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_8.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_9.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_10.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_11.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_12.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_13.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_14.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_15.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_16.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_17.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_18.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_19.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_20.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_21.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_22.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_23.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_24.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_25.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_26.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_27.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_28.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_29.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_30.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_31.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_32.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_33.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_34.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_35.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_36.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_37.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_38.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_39.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_40.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_41.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_42.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_43.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_44.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_45.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_46.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_47.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_48.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_49.jpg,http://cdn.lauc.us/photos/large/WP1AD29PX9LA64805_50.jpg</images> <days>612</days> </vehicle> 文件的示例供参考。

{{1}}

1 个答案:

答案 0 :(得分:0)

从你的例子来看,假设你做了所有其余的解析,你得到了:

NSString *allURLs = @"http://image1.jpg,http://image2.jpg,http://image3.jpg";

您可以在数组中获取所有URL(对于循环很有用),如下所示:

NSArray *arrayOfImagesURLs = [allURLs componentsSeparatedByString:@","];