0

Following is my code block:

    NSArray *innerArrayOfItems = [dictionaryOfItems objectForKey:kXMLNodeChildArray];
    NSString *key = [[NSString alloc] init];
    NSString *value = [[NSString alloc] init];

    for (NSDictionary *innerDictionaryOfItems in innerArrayOfItems) 
    {
      NSArray *keyValueOfString = [innerDictionaryOfItems objectForKey:kXMLNodeChildArray];

      for (NSDictionary *innerDictonaryOfkeyValueOfString in keyValueOfString)
      {
        if ([[innerDictonaryOfkeyValueOfString objectForKey:kXMLNodeName] isEqualToString:@"Key"])
        {
          key = [innerDictonaryOfkeyValueOfString objectForKey:kXMLNodeContent];
        }

        if ([[innerDictonaryOfkeyValueOfString objectForKey:kXMLNodeName] isEqualToString:@"Value"])
        {
          value = [innerDictonaryOfkeyValueOfString objectForKey:kXMLNodeChildArray];
          NSArray *valueArray = [innerDictonaryOfkeyValueOfString objectForKey:kXMLNodeChildArray];

          for (NSDictionary *valueDictionary in valueArray) 
          {
            if ([[valueDictionary objectForKey:kXMLNodeName] isEqualToString:@"ItemTypeAlias"])
           {
             for (NSDictionary *entity_Key_ViewNameDictionary in theDelegate.entity_Key_ViewNameArray) 
             {
               if ([[[entity_Key_ViewNameDictionary allValues] objectAtIndex:0] 
                      isEqualToString:[valueDictionary objectForKey:kXMLNodeContent]])
               {
                 [dataTableArrayDeleted addObject:[[entity_Key_ViewNameDictionary allKeys] objectAtIndex:0]];
                 break;
               }
             }
             //Getting DataTable Primary Key column name

             for (NSDictionary *tables_PrimaryKey_TableNameDictionary 
                  in theDelegate.tables_PrimaryKey_TableNameArray) 
             {
               if ([[[tables_PrimaryKey_TableNameDictionary allKeys] objectAtIndex:0] 
                      isEqualToString:[dataTableArrayDeleted lastObject]])

               {
                 [dataTableKeyColumnArrayDeleted 
                   addObject:[[tables_PrimaryKey_TableNameDictionary allValues] objectAtIndex:0]];

                 isDataAvailabeleForSaveDelete = TRUE;
                 break;
               }
             }
           }
         }
       }
     }

    [self saveGetDataUpdatesDeletedData:key :value];
  }

The above code , look into the objects populated by xml parser and look inside each node from parent node to child nodes (conditional) ,

There is another block in xml which is the additional information of above xml node collection, after looking inside of above loop it will store all the found values to an object and later it comes to another block and search detail of the stored values.

Is there any other proper way of doing xml reading/parsing and storing values in variables?

Thanks, Imran Rizvi

AndersK
  • 35,813
  • 6
  • 60
  • 86
Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101

3 Answers3

1

You allocate key and value but later you just overwrite them without releasing them

NSString *key = [[NSString alloc] init];
NSString *value = [[NSString alloc] init];

probably better to initially set them to nil instead.

AndersK
  • 35,813
  • 6
  • 60
  • 86
  • Can you send code to initially set them nil, If I set it nil immidiately after allocation will it not give me exception/ – Imran Rizvi Nov 08 '11 at 12:06
  • after visiting project again and again and changing all these repairing of miss outs, finally we overcome the issue – Imran Rizvi Mar 19 '12 at 06:41
0

You should use NSXMLParser, here's an example:

The example is from iOS Developer Library. Here's a quick overview about the example:

The SeismicXML sample application demonstrates how to use NSXMLParser to parse XML data. When you launch the application it downloads and parses an RSS feed from the United States Geological Survey (USGS) that provides data on recent earthquakes around the world. It displays the location, date, and magnitude of each earthquake, along with a color-coded graphic that indicates the severity of the earthquake. The XML parsing occurs on a background thread using NSOperation and updates the earthquakes table view with batches of parsed objects.

You should look at the class ParseOperation.

3lvis
  • 4,190
  • 1
  • 30
  • 35
0

Not a real answer .. but what about using TBXML

its fast, easy and you can easily mange memory! If you are a beginner then I strongly recommand TBXML.

Saurabh
  • 22,743
  • 12
  • 84
  • 133