0

我是电话编程的新手。从 Web 服务调用中,我得到了响应,我必须从中获取数据。我已经尽我所能但无法做到这一点..我需要(这两个问题,即你童年最好的名字是什么?以及你的出生地是什么?)标签帮助中的值... .. 下面是我必须解析的 xml 响应....

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns1:isForgotPasswordResponse xmlns:ns1="http://ws.esb.pmp2.ilantus.com/">
         <ns1:return>
            <ns2:attributes xsi:nil="true" xmlns:ns2="http://vo.common.pmp2.ilantus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <ns2:editAllAttributesBean xsi:nil="true" xmlns:ns2="http://vo.common.pmp2.ilantus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <ns2:loginBean xmlns:ns2="http://vo.common.pmp2.ilantus.com">
               <ns2:changePwdOnNextLogon>false</ns2:changePwdOnNextLogon>
               <ns2:host>localhost</ns2:host>
               <ns2:lock>false</ns2:lock>
               <ns2:loginId>pxpuser1002</ns2:loginId>
               <ns2:loginPassword>Passw0rd</ns2:loginPassword>
               <ns2:newPassword xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:oldPassword xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:role>Help Desk User Role</ns2:role>
               <ns2:seedvalue>5VIQPHRXOBTMGRID</ns2:seedvalue>
               <ns2:user xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            </ns2:loginBean>
            <ns2:policyBeans xsi:nil="true" xmlns:ns2="http://vo.common.pmp2.ilantus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <ns2:profileBean xmlns:ns2="http://vo.common.pmp2.ilantus.com">
               <ns2:attributes xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:email>Not specified</ns2:email>
               <ns2:firstName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:isRegistered xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:lastName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:loginBean xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:username xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            </ns2:profileBean>
            <ns2:qnABeans xsi:nil="true" xmlns:ns2="http://vo.common.pmp2.ilantus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <ns2:questions xmlns:ns2="http://vo.common.pmp2.ilantus.com">
               <ns2:Attribute>
                  <ns2:attributeName>question1</ns2:attributeName>
                  <ns2:category xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:editable xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:entity_name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:operation xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:options xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:required xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:sequence>0</ns2:sequence>
                  <ns2:type xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:value>What was the name of your childhood best fr?</ns2:value>
               </ns2:Attribute>
               <ns2:Attribute>
                  <ns2:attributeName>question2</ns2:attributeName>
                  <ns2:category xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:editable xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:entity_name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:operation xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:options xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:required xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:sequence>0</ns2:sequence>
                  <ns2:type xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:value>Which is your place of birth?</ns2:value>
               </ns2:Attribute>
            </ns2:questions>
            <ns2:reportBean xsi:nil="true" xmlns:ns2="http://vo.common.pmp2.ilantus.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <ns2:secondFactorBean xmlns:ns2="http://vo.common.pmp2.ilantus.com">
               <ns2:attributes>
                  <ns2:Attribute>
                     <ns2:attributeName>End User Role</ns2:attributeName>
                     <ns2:category xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:editable xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:entity_name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:operation xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:options xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:required xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:sequence>0</ns2:sequence>
                     <ns2:type xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:value>Enabled</ns2:value>
                  </ns2:Attribute>
                  <ns2:Attribute>
                     <ns2:attributeName>Help Desk User Role</ns2:attributeName>
                     <ns2:category xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:editable xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:entity_name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:operation xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:options xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:required xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:sequence>0</ns2:sequence>
                     <ns2:type xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:value>Enabled</ns2:value>
                  </ns2:Attribute>
                  <ns2:Attribute>
                     <ns2:attributeName>Administrator Role</ns2:attributeName>
                     <ns2:category xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:editable xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:entity_name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:operation xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:options xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:required xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:sequence>0</ns2:sequence>
                     <ns2:type xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <ns2:value>Disabled</ns2:value>
                  </ns2:Attribute>
               </ns2:attributes>
               <ns2:emailTemplate>Dear {0}, 
 
Please find the back up code for your multi factor authentication. 
Back up code:{1} 
Please configure your code manually, if you delete your entry from Google authenticator accidentally. 
 
Thank you, 
TEAM PXP. 
 
 
N.B. Please do not reply to this mail, as it is not monitored.</ns2:emailTemplate>
               <ns2:secondFactor>true</ns2:secondFactor>
               <ns2:statusBean>
                  <ns2:errorCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:errorMessage xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <ns2:result>true</ns2:result>
               </ns2:statusBean>
            </ns2:secondFactorBean>
            <ns2:statusBean xmlns:ns2="http://vo.common.pmp2.ilantus.com">
               <ns2:errorCode>PXPERROR11033</ns2:errorCode>
               <ns2:errorMessage>Either challenge or response or both not found for the user.pxpuser1002</ns2:errorMessage>
               <ns2:result>true</ns2:result>
            </ns2:statusBean>
         </ns1:return>
      </ns1:isForgotPasswordResponse>
   </soap:Body>
</soap:Envelope>
4

1 回答 1

2
NSMutableString *xmlString;

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)nameSpaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    xmlString = [[NSMutableString alloc] init];    
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [xmlString appendString:string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{    
    if ([elementName isEqualToString:@"ns2:value"])
    {
        if (![xmlString isEqual:@""])
        {
            NSLog(@"%@",xmlString);
            [SomeArray addObject:xmlString];
        }
    }

    //Release string
    [xmlString release];
    xmlString = nil;
}

NSMutableString是一个变量,它跟踪foundCharacters方法中的当前元素,并使用 elementName 附加字符串和didEndElement方法,我们可以识别该标记的值。

更新

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    //update your UI here after parsing is finished
}
于 2013-03-26T09:36:31.740 回答