How can i Parse this xml using NSXMLParser in ios?

后端 未结 3 1841
日久生厌
日久生厌 2020-12-16 05:08

    Radio1http://app.syndicat         


        
      
      
      
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 05:34

    Ok you asked for a libxml example. I used it in a project but with TBXML instead of NSXMLParser because this one caused important problems of encoding and data retrieving.

    First you have to download TBXML.m and TBXML.h files from the web and import them into your project. Then you also have to link libxml2.dylib to your project in Link Binary with Libraries.

    Once this done, you will have to do this to retrieve your data (based on your XML source) :

    NSData *xmlData = [NSData dataWithContentsOfURL:yourURL];
    TBXML *tbxml = [TBXML newTBXMLWithXMLData:data error:nil];
    [self getData:tbxml.rootXMLElement];
    
    - (void) getData : (TBXMLElement *) element
    {
        do {
            if([[TBXML elementName:element] isEqualToString:@"table"])
            {
                if([[TBXML elementName:element] isEqualToString:@"column"])
                { 
                    if([[TBXML attributeName:element] isEqualToString:@"nameradio"])
                    {
                        // You decide what to do here
                    }
                }
            }
            if (element->firstChild) [self getData:element->firstChild];
        } while(element = element->nextSibling);
    }
    

    You probably will have to change this code but here you have all the basic things you need.

提交回复
热议问题