【发布时间】:2015-06-08 16:56:27
【问题描述】:
我知道 XML 解析在论坛上已经解释过很多次了,但是我有一个 XML 数据,我无法在我的 Objective-C 项目中解析它。
以下是我拥有的 XML:
<cimpleML xmlns="http://www.example.org/cimple">
<Analytics segmentDelay="15000" serverUrl="http://adjingo.2cimple.com/adserver/analytics.xml" id="1"/>
<Campaign videoId="http://adjingo.s3.amazonaws.com/151/Video/6337.flv" publisherId="151" id="4151"/>
<Template orientation="vertical" bgGradientAlphas="" bgGradientRatio="0.5" bgGradientColors="0" bgColor="0" height="435.0" width="470.0" id="4375">
<div borderAlpha="1.0" borderColor="0" bgColor="0xffffff" splashResize="false" splashImage="" alpha="1.0" height="435.0" width="470.0" y="0.0" x="0.0" id="4352"/>
<videoCanvas actual_width="0.0" actual_height="0.0" bgColor="0" height="235.0" width="460.0" y="5.0" x="4.0" id="0"/>
<girgit>
<adunit transitionEffectDuration="1.0" transitionEffect="alpha" showOnce="false" duration="10.0" id="9392">
<displayApp panelType="normal" panelActivation="null" panel="right" divId="4352">
<renderingData id="6832">
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><application backgroundAlpha="0" backgroundColor="0xD6EDFF" backgroundGradientAlpha="[]" backgroundGradientColor="[]" height="295" width="211"><image id="12771" click="getURL('http://adjingo.2cimple.com/adserver/urlmap/redirectUrl/ac0cb032-4144-48b0-b4d9-aa5d9944a743?campId=4151')" height='435.0' width='470.0' x='0.0' y='0.0' source='http://adjingo.2cimple.com/content/151/Image/6291.jpg' ><keyframes><keyframe x="0.0" y="0.0" width="470.0" height="435.0" alpha="1.0" framenumber="0" /></keyframes></image></application>]]>
</renderingData>
</displayApp>
</adunit>
<adunit transitionEffectDuration="1.0" transitionEffect="alpha" showOnce="false" duration="10.0" id="9393">
<displayApp panelType="normal" panelActivation="null" panel="right" divId="4352">
<renderingData id="6833">
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><application backgroundAlpha="0" backgroundColor="0xD6EDFF" backgroundGradientAlpha="[]" backgroundGradientColor="[]" height="295" width="211"><image id="12772" click="getURL('http://adjingo.2cimple.com/adserver/urlmap/redirectUrl/ac0cb032-4144-48b0-b4d9-aa5d9944a743?campId=4151')" height='435.0' width='470.0' x='0.0' y='0.0' source='http://adjingo.2cimple.com/content/151/Image/6290.jpg' ><keyframes><keyframe x="0.0" y="0.0" width="470.0" height="435.0" alpha="1.0" framenumber="0" /></keyframes></image></application>]]>
</renderingData>
</displayApp>
</adunit>
</girgit>
<panels/>
</Template>
<Skin url="http://adjingo.2cimple.com/cimple/assets/Skin.swf"/>
<Ads/>
</cimpleML>
我实际上想要在videoId= 和source= 之后编写的视频和图像链接,并且我想在我的屏幕上显示它们。但是,根据我的尝试,我无法获取所需的数据。
这是我尝试过的:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// If the current element name is equal to "cimpleML" then initialize the temporary dictionary.
if ([elementName isEqualToString:@"cimpleML"]) {
self.dictTempDataStorage = [[NSMutableDictionary alloc] init];
}
// Keep the current element.
self.currentElement = elementName;
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"renderingData"]) {
// If the closing element equals to "renderingData" then the all the data inside it has been parsed and the dictionary should be added to the data array.
[self.arrData addObject:[[NSDictionary alloc] initWithDictionary:self.dictTempDataStorage]];
}
else if ([elementName isEqualToString:@"adunit"]){
// If the adunit element was found then store everything inside it.
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:@"adunitData"];
}
}
请帮助我走上正轨。非常感谢您的宝贵时间。
【问题讨论】:
标签: ios objective-c xml parsing