简体   繁体   中英

Nsxml parser in iOS

I am new in I phone programming. From the web service call i got a response and from that I have to get the data. I have tried everything i could but was unable to do that..I need the (the two questions ie what was the name of your childhood best fr? and what is your place of birth?) value inside the tag help plz..... Below is the xml response which i have to parse....

<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>
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;
}

Here NSMutableString is a variable that keeps track of the current element in foundCharacters method, and append the string and on didEndElement method using elementName we can recognize value for that tag.

UPDATE

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    //update your UI here after parsing is finished
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM