我必须将解析的 XML 文件的所有相同属性加入到NSMubableDictionary
.
我需要字典中有关"show1"、"show2"等的所有内容(即 " "show1"、"show2"等...键和NSArrays
属于每个键的属性。
我正在使用 RaptureXML 库来解析内容:
RXMLElement *rootXML = [RXMLElement elementFromXMLString:string
encoding:NSUTF8StringEncoding];
[rootXML iterateWithRootXPath:@"//audio" usingBlock: ^(RXMLElement *program) {
NSString * show = [NSString stringWithString:[program attribute:@"program"]];
NSString * date = [NSString stringWithString:[program attribute:@"date"]];
NSString * time = [NSString stringWithString:[program attribute:@"time"]];
NSString * path = [NSString stringWithString:[program attribute:@"path"]];
}];
}
这是 XML 文件:
<audio date="11/01/2012" time="12:00 to 13:00" program="show1" path="http://mydomain/onDemand/audio_12.mp3"/>
<audio date="11/01/2012" time="11:00 to 12:00" program="show2" path="http://mydomain/onDemand/audio_11.mp3"/>
<audio date="11/01/2012" time="10:00 to 11:00" program="show2" path="http://mydomain/onDemand/audio_10.mp3"/>
<audio date="11/01/2012" time="09:00 to 10:00" program="show2" path="http://mydomain/onDemand/audio_09.mp3"/>
<audio date="11/01/2012" time="08:00 to 09:00" program="show3" path="http://mydomain/onDemand/audio_08.mp3"/>
<audio date="11/01/2012" time="07:00 to 08:00" program="show3" path="http://mydomain/onDemand/audio_07.mp3"/>
<audio date="11/01/2012" time="06:00 to 07:00" program="show3" path="http://mydomain/onDemand/audio_06.mp3"/>
<audio date="11/01/2012" time="05:00 to 06:00" program="show4" path="http://mydomain/onDemand/audio_05.mp3"/>
<audio date="11/01/2012" time="04:00 to 05:00" program="show4" path="http://mydomain/onDemand/audio_04.mp3"/>
<audio date="11/01/2012" time="03:00 to 04:00" program="show4" path="http://mydomain/onDemand/audio_03.mp3"/>
我怎样才能做到这一点?有没有更好的方法来解决这个问题?谢谢!