iPhone的XML解析

iPhone的XML解析,iphone,xml,parsing,Iphone,Xml,Parsing,我有一根绳子: <?xml version="1.0" encoding="UTF-8"?> SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:methods" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in

我有一根绳子:

 <?xml version="1.0" encoding="UTF-8"?>
    SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:methods" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:PingdomAPI" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:createAccountResponse><return xsi:type="ns2:CreateAccountResponse"><status xsi:type="xsd:int">3</status><password xsi:nil="true"/></return></ns1:createAccountResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP-ENV:Envelope xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/“xmlns:ns1=”urn:methods“xmlns:xsd=”http://www.w3.org/2001/XMLSchema“xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xmlns:ns2=”urn:PingdomAPI“xmlns:SOAP-ENC=”http://schemas.xmlsoap.org/soap/encoding/“SOAP-ENV:编码风格="http://schemas.xmlsoap.org/soap/encoding/">3
问题是:如何提取int值3,即状态值。

您需要使用(或第三方解决方案)。
有关更多信息和有用的包装,请参阅。

这些示例取自苹果的e

创建和初始化NSXMLParser实例:

BOOL success;
NSURL *xmlURL = [NSURL fileURLWithPath:pathToFile];
if (addressParser) // addressParser is an NSXMLParser instance variable
    [addressParser release];
addressParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[addressParser setDelegate:self];
[addressParser setShouldResolveExternalEntities:YES];
success = [addressParser parse]; // return value not used
            // if not successful, delegate is informed of error
实现您感兴趣的委托方法

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

有关委托方法的完整列表,请参见。

NSXML仅在模拟器中可用,但由于性能问题,在设备本身上不可用。MLaden,你是正确的,但rjstelling的示例使用NSXMLParser,它在设备上可用。我将如何实现这一点来解决我的问题。我建议使用strin的内容初始化addressParserg而不是URL。但是如何提取键“status”的int值?Mladen您需要实现didStartElement:和parse:foundCharacters:您确实需要阅读文档(和/或我的博客文章)。没有太多内容。我们可以帮助您解决可能存在的特定问题。