如果iPhone编程中节点不连续,如何使用NSXMLParser?
我有以下链接,从以下链接返回 XML
http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=24.827774,67.034367 //This is URLString link
NSXMLParser *xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:
[NSString stringWithFormat:@"%@",URLString]]];
[xmlParser setDelegate:self];
[xmlParser parse];
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
我只想保存“城市”“天气”“temp_f”和“temp_c”的值,以便在标签上显示;
我真的对 NSXMLParser 解析总是感到困惑,如果有人能用好词来定义,我将不胜感激,以便我对 NSXMLParser 得到正确的理解
提前谢谢
I have following link, returning XML as from following link
http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=24.827774,67.034367 //This is URLString link
NSXMLParser *xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:
[NSString stringWithFormat:@"%@",URLString]]];
[xmlParser setDelegate:self];
[xmlParser parse];
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
I want to save only values of "city" "weather" "temp_f" and "temp_c" so for displaying on labels;
I am really get confuse always about NSXMLParser parsing, I would be thankful if someone will define in good words, so that I get proper understanding of NSXMLParser
Thank you in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
didEndElement
委托方法中检查elementName
。您可以对所需的其他值执行相同的操作。
In your
didEndElement
delegate method check for theelementName
.You can do the same for the other values you want.