当我在不同类别中有多个同名节点时,如何使用 NSXMLParser 读取 XML?

发布于 2024-12-01 18:49:29 字数 1737 浏览 0 评论 0原文

我怎样才能使用 NSXMLParser 进行这种类型的 XML 响应,我对两次“点击”感到困惑,它会击中,那么如何使用一个对象来管理流程并保存数据,请帮帮我,

</campaign_summary_response>

<summary> <clicks>6</clicks>
<conversions>1</conversions>      
<conversion_rate>0.1666666666666666666666666667</conversion_rate>     
<revenue>22.26555000000000</revenue> 
<revenue_converted>22.26555000000000</revenue_converted>     
<currency_symbol>$</currency_symbol>  
<currency_symbol_converted>$</currency_symbol_converted>
</summary>

<campaigns>
<campaign> <offer_id>100</offer_id>
<offer_name>$100 Wendy's Gift Card + Free Frosty</offer_name>     
<campaign_id>1781</campaign_id> <vertical_name>Free Stuff</vertical_name> 
<price_format>CPA</price_format>
<price>0.0000</price> 
<impressions>0</impressions>
<clicks>6</clicks>   
<conversions>1</conversions>
<conversion_rate>0.1666666666666666666</conversion_rate>  
<revenue>15.0000</revenue>
<revenue_converted>22.26555000000000</revenue_converted> 
<epc>2.50000000000000000000000</epc>
<currency_symbol>€</currency_symbol>   
<currency_symbol_converted>$</currency_symbol_converted>
</campaign> </campaigns>

</campaign_summary_response>

我如何按照委托方法进行编码

    - (void)parser:(NSXMLParser *)parser 
               didEndElement:(NSString *)elementName
               namespaceURI:(NSString *)namespaceURI 
               qualifiedName:(NSString *)qName {

所以我可以将所有值保存在一个对象中并在显示器上显示。

How can I such type of Response of XML, using NSXMLParser, I am confused about two "clicks", it will hit, so how to manage flow and save data with one object, help me out,

</campaign_summary_response>

<summary> <clicks>6</clicks>
<conversions>1</conversions>      
<conversion_rate>0.1666666666666666666666666667</conversion_rate>     
<revenue>22.26555000000000</revenue> 
<revenue_converted>22.26555000000000</revenue_converted>     
<currency_symbol>
lt;/currency_symbol>  
<currency_symbol_converted>
lt;/currency_symbol_converted>
</summary>

<campaigns>
<campaign> <offer_id>100</offer_id>
<offer_name>$100 Wendy's Gift Card + Free Frosty</offer_name>     
<campaign_id>1781</campaign_id> <vertical_name>Free Stuff</vertical_name> 
<price_format>CPA</price_format>
<price>0.0000</price> 
<impressions>0</impressions>
<clicks>6</clicks>   
<conversions>1</conversions>
<conversion_rate>0.1666666666666666666</conversion_rate>  
<revenue>15.0000</revenue>
<revenue_converted>22.26555000000000</revenue_converted> 
<epc>2.50000000000000000000000</epc>
<currency_symbol>€</currency_symbol>   
<currency_symbol_converted>
lt;/currency_symbol_converted>
</campaign> </campaigns>

</campaign_summary_response>

How do I code following delegate method

    - (void)parser:(NSXMLParser *)parser 
               didEndElement:(NSString *)elementName
               namespaceURI:(NSString *)namespaceURI 
               qualifiedName:(NSString *)qName {

So that i can save all values in one object and show on display.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-12-08 18:49:29

didStartElement 方法中。

if([elementName isEqualToString:@"summary"]) summary = YES;
if([elementName isEqualToString:@"campaign"]) campaign = YES;

didEndElement 方法中。

if(summary) {

    if([elementName isEqualToString:@"revenue"]) // revenue in summary
    if([elementName isEqualToString:@"summary"]) summary = NO;
}

if(campaign) {

    if([elementName isEqualToString:@"revenue"]) // revenue in campaign
    if([elementName isEqualToString:@"campaign"]) campaign = NO;
}

In didStartElement method.

if([elementName isEqualToString:@"summary"]) summary = YES;
if([elementName isEqualToString:@"campaign"]) campaign = YES;

In didEndElement method.

if(summary) {

    if([elementName isEqualToString:@"revenue"]) // revenue in summary
    if([elementName isEqualToString:@"summary"]) summary = NO;
}

if(campaign) {

    if([elementName isEqualToString:@"revenue"]) // revenue in campaign
    if([elementName isEqualToString:@"campaign"]) campaign = NO;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文