简体   繁体   中英

IPhone SDK : Help me about xml parsing with TBXML

i have a connection with a webservice, recieved data is not equals to "nil" and the response SOAP UI show is this;

<soap:Envelope
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
>
-<soap:Body>
 -<GroupResponse xmlns="http://tempuri.org/">
  -<GroupResult>
   -<GroupClass>
     -<Groupid>48937</Groupid>
     -<GroupName>test</GroupName>
       -<Members>
        -<MemberClass>
            -<memberID>4699860</memberID>
            -<memberNAME>nazan</memberNAME>
            -<memberLASTNAME>torun</memberLASTNAME>
            -<memberPHONE>292930412452</memberPHONE>
            -<memberBIRTH>02.04.1980</memberBIRTH>
            -<memberMARRIAGE>01.11.2009</memberMARRIAGE>
         </MemberClass>
        -<MemberClass>
              ...has lots of member

how can i get theese with TBXML ? this is my code, but it crashes..

NSArray *propertyArray = [NSArray arrayWithObjects:@"Members",@"memberID",@"memberNAME",@"memberLASTNAME",@"memberPhone",@"memberBIRTH",@"memberMARRIAGE",nil];

TBXML * tbxml = [[TBXML alloc] initWithXMLData:GrupRecievedData];
        TBXMLElement *root = tbxml.rootXMLElement;
        if (root) {
            NSLog(@"root: %@",[TBXML elementName:root]);

            TBXMLElement *item = [TBXML childElementNamed:@"soap:Body" parentElement:root];
            TBXMLElement *item1 = [TBXML childElementNamed:@"GroupResponse" parentElement:item];
            TBXMLElement *item2 = [TBXML childElementNamed:@"GroupResult" parentElement:item1];
            TBXMLElement *item3 = [TBXML childElementNamed:@"Groupid" parentElement:item2];
            TBXMLElement *item4 = [TBXML childElementNamed:@"GroupName" parentElement:item3];
            TBXMLElement *item5 = [TBXML childElementNamed:@"Members" parentElement:item4];

i tried to parse with objects in array, but i crashes on " TBXMLElement *item1 = [TBXML childElementNamed:@"GroupResponse" parentElement:item]; " i dont have any idea anything about solving this problem..

Place a breakpoint on root and in debugger window expand root see if you have childElement soap:Body then expand childElement soap:Body see if you have childElement GroupResponse..From the XML you posted I tried it out it works fine until Groupid , Groupid, GroupName,Members are siblings, MemberClass is firstChild of Member, MemberId is firstChild of memberclass, MemberName, MemberPhone.etc are nextSiblings of MemberId. 在此处输入图片说明

Have you tried setting a break point and stepping through the code to see what each call is actually returning? Also, the error it crashes with would help. My first guess would be that [TBXML childElementNamed:@"soap:Body" parentElement:root] is returning nil. Then on the next line you are looking for the child of the nil "item" which the TBXML code probably doesn't like.

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