1

我如何在 Xcode 中解析这个 xml。这很紧急。

<?xml version="1.0" encoding="utf-8"?>
<url>
    <string name="address">SomeValue</string>
</url>
4

1 回答 1

2

看看下面的代码,它可能对你有帮助:)

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
       attributes:(NSDictionary *)attributeDict {

        if([elementName isEqualToString:@"string"])
            urlStr = [[NSString alloc] init];

    }

    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
        if(!currentElementValue)
            currentElementValue = [[NSString alloc] init];

        currentElementValue = [NSString stringWithFormat:@"%@",string];
    }

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if([elementName isEqualToString:@"string"])
           urlStr = [NSString stringWithString:currentElementValue];

    }

    - (void)parserDidEndDocument:(NSXMLParser *)parser {

    }
于 2013-03-26T07:06:09.167 回答