Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 27, 2013, 11:47 PM   #1
jennylcf
macrumors newbie
 
Join Date: Jan 2013
parsing and displaying in tableview

I'm having a hard time displaying my xml in my tableview. I parse it successfully using NSXMLparser but when i am retrieving the data and trying display it on my table view the output is not complete. I have 3 tableviews, 1 is for the list of countries the 2nd is for the list of <subsidiary> the 3rd is for the information. The problem occurs when 1 country has 2 or more <subsidiary>, it only display the last subsidiary of that country. here is my xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<countries>
    <country>
            <countryname>Philippines</countryname>
            <subsidiaries>
                    <subsidiary>
                            <name id = "1">Sartorius Philippines Inc.</name>
                            <address>Unit 20-A The World Centre Building, 330 Senator Gil Puyat Avenue Makati 1209 City Philippines, Philippines</address>
                            <phone>+63.2.8640.929</phone>
                            <fax>+63.28640.932</fax>
                            <email>enquiry.philippines@sartorius.com</email>
                            <website>http://www.sartorius-mechatronics.com.ph</website>
                    </subsidiary>
            </subsidiaries>
    </country>
    <country>
        <countryname>Denmark</countryname>
            <subsidiaries>
                <subsidiary>
                        <name>Sartorius Stedim Nordic A|S</name>
                        <address>stedim Hoerskaetten 6d 2630 Taastrup, Denmark</address>
                        <phone>+45.7023.4400</phone>
                        <fax>+45.4630.4030</fax>
                        <email>ne.customersupport@sartorius.com</email>
                        <website></website>
                </subsidiary>
                <subsidiary>
                        <name>Sartorius Nordic A|S</name>
                        <address>Hoerskaetten 6D 2630 Taastrup, Denmark</address>
                        <phone>+45.7023.4400</phone>
                        <fax>+45.4630.4030</fax>
                        <email>ne.customersupport@sartorius.com</email>
                        <website></website>
                </subsidiary>
            </subsidiaries>
    </country>
</countries>
as you can see the <countryname> Denmark has two <subsidiary> in it. can you help me display all the subsidiary in that country?

here is my parser class, DON'T MIND THE app.infoarray,



Code:
#import "Parser.h"

@implementation Parser


-(id)initParser
{
    if (self == [super init])
    {
        app = (AppDelegate *) [[UIApplication sharedApplication]delegate];
    }

    return self;
}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqualToString:@"countries"])
    {
           app.listArray = [[NSMutableArray alloc]init];
           app.infoarray = [[NSMutableArray alloc]init];
    }
  if ([elementName isEqualToString:@"country"])
    {
        theList = [[List alloc]init];
        temp = [[NSMutableString alloc]init];
    }
    if ([elementName isEqualToString:@"subsidiary"]) {
        theList.countryname = temp;
        [app.infoarray addObject:theList.countryname];
    }
   
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        
}


-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"subsidiary"])
    {
        [app.listArray addObject:theList];
    }
    else
    {
         if ([elementName isEqualToString:@"countryname"])
         {
             temp = currentElementValue;
          
         }
        if ([elementName isEqualToString:@"name"])
        {
            
            theList.name = currentElementValue;
          
         
        }
        if ([elementName isEqualToString:@"address"])
        {
            theList.address = currentElementValue;
           
        }
        if ([elementName isEqualToString:@"phone"])
        {
            theList.phone = currentElementValue;
            
        }
        if ([elementName isEqualToString:@"fax"])
        {
            theList.fax = currentElementValue;
          
        }
        if ([elementName isEqualToString:@"email"])
        {
            theList.email = currentElementValue;
           
        }
        if ([elementName isEqualToString:@"website"])
        {
            theList.website = currentElementValue;
            
        }
        
       currentElementValue = nil;
       
    }

}

@end

Last edited by stridemat; Jan 28, 2013 at 01:06 AM. Reason: Please use code tags
jennylcf is offline   0 Reply With Quote
Old Jan 28, 2013, 05:08 AM   #2
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I can't see how your subsidiary information gets associated with a country at all... It looks like all of the subsidiary information goes in a single app.listarray?

How do you know your issue is with what you've shown us and not your Table View Controller?
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 28, 2013, 06:31 AM   #3
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Quote:
Originally Posted by ArtOfWarfare View Post
I can't see how your subsidiary information gets associated with a country at all... It looks like all of the subsidiary information goes in a single app.listarray?

How do you know your issue is with what you've shown us and not your Table View Controller?
There is no association between the subsidiary and the country. He would have to create a country object that can contain and array of subsidiary objects, or he would have to make the entire list only subsidiary objects and add a country property to each subsidiary as he creates the new instances to add them to the array. This would allow him to filter the array based on country and only get the elements where the country property is the country he is looking for. He can also get a list from the subsidiaries of all unique countries to populate the list from one set of data.
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
JSON Parsing and put in TableView+Hierarchy mehdies iPhone/iPad Programming 2 Nov 30, 2013 10:28 AM
RSS parsing help (simple) johnnyfla123 iPhone/iPad Programming 12 Nov 29, 2013 10:16 AM
Parsing hidden WebView items. mycompuser iPhone/iPad Programming 1 Aug 2, 2013 12:20 AM
parsing XML in iphone? hajira iPhone 0 Sep 24, 2012 04:51 AM
Parsing text/html MKNetworkKit nashyo iPhone/iPad Programming 2 Jun 30, 2012 04:21 AM

Forum Jump

All times are GMT -5. The time now is 03:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC