如果iPhone编程中节点不连续,如何使用NSXMLParser?

发布于 2024-12-04 02:53:53 字数 1113 浏览 0 评论 0原文

我有以下链接,从以下链接返回 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 技术交流群。

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

发布评论

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

评论(1

婴鹅 2024-12-11 02:53:53

在您的 didEndElement 委托方法中检查 elementName

if (elementName isEqualtoString:@"city"])
// Save the element which is currently holding the value from the `foundCharacters` delegate method into your variable.

您可以对所需的其他值执行相同的操作。

In your didEndElement delegate method check for the elementName.

if (elementName isEqualtoString:@"city"])
// Save the element which is currently holding the value from the `foundCharacters` delegate method into your variable.

You can do the same for the other values you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文