Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:02:23+00:00 2026-05-26T05:02:23+00:00

Please anybody help me.i am in great trouble….Now my Problem is… Using xml parser

  • 0

Please anybody help me.i am in great trouble….Now my Problem is…

Using xml parser i have parsed some attribute and value of the attribute.

using this i am getting the element name:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName   namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:   (NSDictionary *)attributeDict

Now using this i am getting value of the attribute from the xml:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 
NSLog(@"found characters: %@ %@", currentElement,string);

suppose my xml data are something like that…

-<list>
−<ProductData HASH="838557843">
<id>1</id>
<productNumber>a91cc0f4c7</productNumber>
<name>Product 1</name>
<seoTitle>product-1</seoTitle>
<viewCount>0</viewCount>
<lowStock>0.0</lowStock>
<image>5e928bbae358c93caedf6115fa7d178b.jpg</image>
<dateCreated>2011-10-06T16:08:45</dateCreated>
<dateUpdated>2011-10-06T10:08:45</dateUpdated>
<isDummy>true</isDummy>
<isInventory>false</isInventory>
</ProductData>
-<ProductData HASH="681596439">
<id>2</id>
<productNumber>d8287e2e51</productNumber>
<name>Product 2</name>
<seoTitle>product-2</seoTitle>
−<description>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,....</p>
</description>
<viewCount>0</viewCount>
<availableStock>100.0</availableStock>
<lowStock>0.0</lowStock>
<image>8bbd8dfff3cdd28285d07810a4fe7c32.jpg</image>
<basePrice>10.0</basePrice>
<costPrice>10.0</costPrice>
<height>1.0</height>
<width>1.0</width>
<depth>1.0</depth>
<weight>3.0</weight>
<status>A</status>
<quantityOrderMin>1.0</quantityOrderMin>
<productIsCall>false</productIsCall>
<quantityOrderMax>20.0</quantityOrderMax>
<priceByAttribute>false</priceByAttribute>
<dateCreated>2011-10-06T16:08:45</dateCreated>
<dateUpdated>2011-10-06T10:08:45</dateUpdated>
<isDummy>true</isDummy>
<isInventory>false</isInventory>
</ProductData>
</list>`

Now when i will get the id attribute then it will store in an array then all of the attribute after first id until next id i want to store the attribute and its value in the dictionary,when i will get second id then i want to continue previous process…then according to the value of id i want to display the value in a UIView or UITableView. its not neccesary where i want to display it.

My question is how can i store data in array and dictionary and display it any time in my viewcontroller. Please help me. its becoming a great trouble for me. if you can please give me a sample code as an example. please please anybody help me…

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:02:24+00:00Added an answer on May 26, 2026 at 5:02 am

    If you change your XML to

    <list>
     <Object>
         <id>1</id>
         <product>name</product>
         <image>imagename.jpg</image>
         <dateCreated>date</dateCreated>
         <productleft>10</productleft>
     </Object>
    
     <Object>
         <id>2</id>
         <product>name</product>
         <image>imagename.jpg</image>
         <dateCreated>date</dateCreated>
         <productleft>30</productleft>
     </Object>
    </list>
    

    Or if your XML looks something like above its easy to use SAX parser ( NSXMLParser you’ve used ). Otherwise if you want to stick to XML you have posted use DOM style parsing.

    Here is the code for the XML after formatting using NSXMLParser.

    // these are ivars
    NSMutableArray * objectsArray;
    NSMutableDictionary * productDict;
    NSMutableString * currentString;
    
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    {
        if([elementName isEqualToString:@"Object"])
        {
            objectsArray = [[NSMutableArray alloc] init];
            productDict = [[NSMutableDictionary alloc] init];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
    {
        if(!currentString)
        {
            currentString = [[NSMutableString alloc] init];
        }
        [currentString appendString:string]; 
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if([elementName isEqualToString:@"id"])
        {
            [productDict setObject:currentString forKey:@"id"];
            [currentString release],currentString = nil;
            return;
        }
        if([elementName isEqualToString:@"product"])
        {
            [productDict setObject:currentString forKey:@"product"];
            [currentString release],currentString = nil;
            return;
        }
        if([elementName isEqualToString:@"image"])
        {
            [productDict setObject:currentString forKey:@"image"];
            [currentString release],currentString = nil;
            return;
        }
        if([elementName isEqualToString:@"dateCreated"])
        {
            [productDict setObject:currentString forKey:@"dateCreated"];
            [currentString release],currentString = nil;
            return;
        }
        if([elementName isEqualToString:@"productleft"])
        {
            [productDict setObject:currentString forKey:@"productleft"];
            [currentString release],currentString = nil;
            return;
        }
        if([elementName isEqualToString:@"Object"])
        {
            [objectsArray addObject:productDict];
            [productDict release],productDict = nil;
        }
        [currentString release], currentString = nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody please help me with this as I have no idea why public
Please anybody help me. i want to display the particular attribute and its value
i am newer to iphone application development so please anybody help me.my main problem
whats wrong with this? anybody help me please.. if(stripos($nerde, $hf) !== false) && (stripos($nerde,
Anybody please give some useful links on this topic.i need to create a content
i have a big problem here..i am using Microsoft charting controls in my asp.net
I have designed a weighted graph using a normalized adjacency list in mysql. Now
I have a text file which was created using some Microsoft reporting tool. The
could please anybody help me to install spring surf ? According to this video
Can anybody please help me with how to get the language(english,chinese etc) of Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.