2013-02-22 94 views
0

我想解析一个看起来像这样的XML。iOS中的XML解析

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<soap:Body> 
    <WM_Login_MobileAppResponse xmlns="A.MobileAppService"> 
     <WM_Login_MobileAppResult> 
      <Login xmlns=""> 
       <Customer_Type>5</Customer_Type> 
       <Token>token</Token> 
      </Login> 
     </WM_Login_MobileAppResult> 
    </WM_Login_MobileAppResponse> 
</soap:Body> 

我试图NSXMLParsesr解析文档。我使用的代码是:

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

if ([elementName isEqualToString:@"WM_Login_MobileAppResult"]) { 
    _resultDict = [[NSMutableDictionary alloc] init]; 
} 
} 

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{ 

[_resultDict setObject:_currentString forKey:elementName]; 
if ([elementName isEqualToString:@"WM_Login_MobileAppResult"]) { 
    [_array addObject:_resultDict]; 
    _resultDict = nil; 
} 
} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
_currentString = [[NSString alloc] initWithString:string]; 
} 

这是我得到的结果:

(
    { 
    "Customer_Type" = 4; 
    Login = "token"; 
    Token = "token"; 
    "WM_Login_MobileAppResult" = "token"; 
} 
) 

是否有人可以帮助我得到适当的回应?

+0

什么是你希望你贴以获取'Login'和'WM_Login_MobileAppResult'为XML字符串? – GeneralMike 2013-02-22 19:11:39

+0

你期望实际得到什么? – 2013-02-22 19:14:41

+0

我期待只存储'Token'和'Customey_Type'的值。 – 2013-02-22 19:59:10

回答

0

,我认为你应该改变“WM_Login_MobileAppResult”到“登录”