Ahmed Malibari
Ahmed Malibari

Reputation: 39

How can I parse XML tags which has same name.. using TBXML?

I have this XML :

<xml encoding="UTF-8">
<URLs>
<contentTypes>
<ROW1>
<link>www.google.com</link>
<link>www.hotmail.com</link>
<link>www.yahoo.com</link>
<link>www.microsoft.com</link>
</ROW1>
</contentTypes>
</URLs>

Now, I want to extract the links and store them in array using TBXML in objective-c.

Thankx in advance,

Upvotes: -2

Views: 140

Answers (2)

Anand Y
Anand Y

Reputation: 329

@Ahmer Mli: I would assume you already know how to parse the xml using TBXML. Here is a test code that would help in your case:

   NSMutableArray links = [[NSMutableArray alloc] init];
   TBXMLElement *rowLink; //I assume you already knew how to get to the <ROW1> element;
   TBXMLElement *linkElement = rowLink->firstChild;
   if (linkElement)
   {
      do
      {
         if ([[TBXML elementName:linkElement] isEqualString@"link"])
         {
            [links addObject:[TBXML textForElement:linkElement]];
         }
      }((linkElement = linkElement->nextSibling));
   }

Upvotes: 0

Venk
Venk

Reputation: 5955

You can convert your xml string into dictionary by using the XMLReader like as follows

NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:resp error:&parseError];

After that you can easily access your data..

Upvotes: 0

Related Questions