开发者

How to fetch inherited xml on iOS?

I'm trying to fetch XML through this code.

NSArray *contacts= [[[[xmlDoc rootElement] elementsForName:@"contacts"] objectAtIndex:0] elementsForName:@"contacts"];

for (开发者_StackOverflow中文版int i = 0; i < [contacts count]; ++i)
            {
contact = [NSMutableDictionary dictionary];
[contact setValue:[[[[contacts objectAtIndex:i] elementsForName:@"contact_name"] objectAtIndex:0] stringValue] forKey:@"name"];

simple xml are fetching easily but complicated like as I shown below given me problem.

Please help me.

<contacts>
        <contact>
          <contact_id>0</contact_id>
        </contact>
      </contacts>


This might help You Faraz

TBXMLElement *invoiceTag = [TBXML childElementNamed:@"invoice" parentElement:root];
while(invoiceTag!=NULL){
    TBXMLElement *invoice_idTag = [TBXML childElementNamed:@"invoice_id" parentElement:invoiceTag];
    TBXMLElement *numberTag = [TBXML childElementNamed:@"number" parentElement:invoiceTag];
    TBXMLElement *contactsTag = [TBXML childElementNamed:@"contacts" parentElement:invoiceTag];
    TBXMLElement *contactTag = [TBXML childElementNamed:@"contact" parentElement:contactsTag];
    while (contactTag!=NULL) {
        TBXMLElement *contact_idTag = [TBXML childElementNamed:@"contact_id" parentElement:contactTag];
        contactTag=contactTag->nextSibling;
    }
}


Finally, I've done this. For those of you who have the same problem check this code.

NSArray *foundRoots = [[xmlDoc rootElement] elementsForName:@"invoice"] ;
    NSLog(@"aaaaaaaaa %@",foundRoots);
    CXMLElement *Root = [foundRoots objectAtIndex:0];
    NSLog(@"root ......... %@",Root);
    NSArray *children = [Root children];
    NSLog(@"childdtee ------- %@",children);

    NSArray *tag1 = [[[Root elementsForName:@"contacts"]objectAtIndex:0]elementsForName:@"contact"];
    NSLog(@"contacts........%@",tag1);

    for (int i = 0; i < [tag1 count]; ++i)
    {
        getDetailInvoice = [NSMutableDictionary dictionary];
        [getDetailInvoice setValue:[[[[tag1 objectAtIndex:i] elementsForName:@"contact_id"] objectAtIndex:0] stringValue] forKey:@"1"];
        [invoiceDetailData addObject:getDetailInvoice];

        NSLog(@"%@",invoiceDetailData);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜