本文介绍了特定标签值的 NSXMLParsing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的 XML 文件:
I have an XML file that looks like this:
<country>
<routes>
<SourceCountry>Ireland</SourceCountry>
<SourcePort>Larne</SourcePort>
<DestinationCountry>UK</DestinationCountry>
<DestinationPort>Troon </DestinationPort>
</routes>
<routes>
<SourceCountry>Ireland</SourceCountry>
<SourcePort>Larne</SourcePort>
<DestinationCountry>UK</DestinationCountry>
<DestinationPort>Cairnryan </DestinationPort>
</routes>
<routes>
<SourceCountry>Ireland</SourceCountry>
<SourcePort>Belfast</SourcePort>
<DestinationCountry>UK</DestinationCountry>
<DestinationPort>Birkenhead </DestinationPort>
</routes>
<routes>
<SourceCountry>Ireland</SourceCountry>
<SourcePort>Belfast</SourcePort>
<DestinationCountry>Belgium</DestinationCountry>
<DestinationPort>Heysham </DestinationPort>
</routes>
<routes>
<SourceCountry>Belgium</SourceCountry>
<SourcePort>Warrenpoint</SourcePort>
<DestinationCountry>UK</DestinationCountry>
<DestinationPort>Heysham </DestinationPort>
</routes>
我想解析 的特定数据;== 爱尔兰和 <DestinationCountry>==英国
.我该怎么做?
I want parse particular data for <SourceCountry> == Ireland and <DestinationCountry> == UK
. How can I do this?
推荐答案
使用 NSXMLParser
为这个类实现委托...
为这个解析器实现方法...
implement the methods for this parser...
您将需要以下方法..
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURIqualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
您可以阅读本教程;使用起来很简单.
You can read this tutorial; it is simple to use.
这篇关于特定标签值的 NSXMLParsing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!