How can i Parse this xml using NSXMLParser in ios?

Emon picture Emon · Mar 2, 2013 · Viewed 23.8k times · Source
<root>
    <table name="radios">
        <column name="nameradio">Radio1</column>
        <column name="logo">http://app.syndicationradio.fr/demo/logo1.png</column>
        <column name="stream">http://cloud2.syndicationradio.fr:8020</column>
        <column name="twitter">http://www.twitter.com/#syndicationradio</column>
        <column name="facebook">http://www.facebook.com/syndicationradio</column>
        <column name="titre">http://app.syndicationradio.fr/demo/title.xml</column>
    </table>
    <table name="radios">
        <column name="nameradio">Radio2</column>
        <column name="logo">http://app.syndicationradio.fr/demo/logo1.png</column>
        <column name="stream">http://cloud2.syndicationradio.fr:8020</column>
        <column name="twitter">http://www.twitter.com/#syndicationradio</column>
        <column name="facebook">http://www.facebook.com/syndicationradio</column>
        <column name="titre">http://app.syndicationradio.fr/demo/title.xml</column>
    </table>
</root>

Now please is there anybody help to find out that, how can i get those url from the xml data using NSXMLParser or any other xml parser suppose TBXML in IOS?

Edit: you can also give me example of libxml parser for this xml.

Thanks In Advance.

Answer

Dharmbir Singh picture Dharmbir Singh · Mar 2, 2013

Try to this one

    - (void)viewDidLoad

   {
      NSURL *url = [[NSURL alloc]initWithString:@"yourURL"];
        NSXMLParser *parser = [[NSXMLParser alloc]initWithContentsOfURL:url];
        [parser setDelegate:self];
       BOOL result = [parser parse];
   }

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    {
        NSLog(@\"Did start element\");
    if ( [elementName isEqualToString:@"root"])
     {
        NSLog(@"found rootElement");
        return;
    }
    }

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        NSLog(@"Did end element");
        if ([elementName isEqualToString:@"root"]) 
            {
              NSLog(@"rootelement end");
            }

    }
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
    {
        NSString *tagName = @"column";

       if([tagName isEqualToString:@"column"])
      {
           NSLog(@"Value %@",string);
      }

    }