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 7430245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:06:27+00:00 2026-05-29T09:06:27+00:00

<list> <OrderData HASH=1408108039></OrderData> <OrderData HASH=208524692> <id>97</id> <customer> <CustomerData HASH=2128670187></CustomerData></customer> <billingAddress></billingAddress><deliveryAddress></deliveryAddress> <orderDetail> <list> <OrderDetailData HASH=516790072></OrderDetailData>

  • 0
<list>
    <OrderData HASH="1408108039"></OrderData>
    <OrderData HASH="208524692">
        <id>97</id>
        <customer>
            <CustomerData HASH="2128670187"></CustomerData></customer>
        <billingAddress></billingAddress><deliveryAddress></deliveryAddress>
        <orderDetail>
            <list>
                <OrderDetailData HASH="516790072"></OrderDetailData>
                <OrderDetailData HASH="11226247"></OrderDetailData>
                <OrderDetailData HASH="11226247"></OrderDetailData>
            </list>
        </orderDetail>
        <log/>
    </OrderData>
    <OrderData HASH="1502226778"></OrderData>
</list>

I cannot find a solution to find the number of OrderDetailData elements? I also read http://iphonebyradix.blogspot.com/2011/03/using-gdata-to-parse-xml-file.html this url.

Thanks in advance.

Edit:

I am explaining my requirement again. In this xml there will be multiple OrderData element. Now I have to count the number of OrderDetailData elemnts from a particular OrderData element. Suppose that, according to my xml, the current parsed xml has one OrderData element, named id and its value is 97. Now, I have to count how many OrderDetailData elements are contained in the OrderData(whichid` is 97).

  • 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-29T09:06:28+00:00Added an answer on May 29, 2026 at 9:06 am

    This is a simple example how to retrieve some data. This example is very simple and not use XPath expression. I suggest you first understand how it works and then use XPath expression. In my opinion it is not useful to use XPath expression if you cannot understand how the parser works.

    NSString* path = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"xml"];
    
    NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:path];
    NSError *error;
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData 
                                                           options:0 error:&error];
    //NSLog(@"%@", doc.rootElement); // print the whole xml
    
    NSArray *orderDataArray = [doc.rootElement elementsForName:@"OrderData"];
    
    for (GDataXMLElement *orderDataElement in orderDataArray) {
    
        if([orderDataElement childCount] > 0)
        {            
            NSString *attributeForOrderDataElement = [(GDataXMLElement *) [orderDataElement attributeForName:@"HASH"] stringValue];   
    
            NSLog(@"attributeForOrderDataElement has value %@", attributeForOrderDataElement);
    
            GDataXMLElement* idElement = (GDataXMLElement*)[[orderDataElement elementsForName:@"id"] objectAtIndex:0];
    
            NSLog(@"id has value %@", idElement.stringValue);
    
            GDataXMLElement* orderDetailElement = (GDataXMLElement*)[[orderDataElement elementsForName:@"orderDetail"] objectAtIndex:0];
    
            GDataXMLElement* listElement = (GDataXMLElement*)[[orderDetailElement elementsForName:@"list"] objectAtIndex:0];            
    
            NSArray* orderDetailDataArray = [listElement elementsForName:@"OrderDetailData"];
    
            int count = 0;
            for (GDataXMLElement *orderDetailDataElement in orderDetailDataArray) {
    
                NSString *attributeForOrderDetailDataElement = [(GDataXMLElement *) [orderDetailDataElement attributeForName:@"HASH"] stringValue];
    
                NSLog(@"attributeForOrderDetailDataElement has value %@", attributeForOrderDetailDataElement);
    
                count++;
            }
    
            NSLog(@"%d", count);
        }
    }
    
    [doc release];
    [xmlData release]; 
    

    This is the output console:

    attributeForOrderDataElement has value 208524692 <-- HASH value
    id has value 97 <-- id value
    attributeForOrderDetailDataElement has value 516790072 <-- HASH value
    attributeForOrderDetailDataElement has value 11226247
    attributeForOrderDetailDataElement has value 11226247
    3 <-- the count
    

    Hope it helps.

    Edit

    test2.xml contains your file but you could pass it as a string. You can also pass as parameters as string like the following:

    NSString* xmlString = @"<list>"
        "<OrderData HASH=\"1408108039\"></OrderData>"
        "<OrderData HASH=\"208524692\">"
        "<id>97</id>"
        "<customer>"
        "<CustomerData HASH=\"2128670187\"></CustomerData>"
        "</customer>"
        "<billingAddress></billingAddress>"
        "<deliveryAddress></deliveryAddress>"
        "<orderDetail>"
        "<list>"
        "<OrderDetailData HASH=\"516790072\"></OrderDetailData>"
        "<OrderDetailData HASH=\"11226247\"></OrderDetailData>"
        "<OrderDetailData HASH=\"11226247\"></OrderDetailData>"
        "</list>"
        "</orderDetail>"
        "<log/>"
        "</OrderData>"
        "<OrderData HASH=\"1502226778\"></OrderData>"
        "</list>";    
    
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmlString options:0 error:&error];  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a list of customer who ordered a particular product for
List Comprehension for me seems to be like the opaque block of granite that
List Comprehension is a very useful code mechanism that is found in several languages,
List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here,
List<tinyClass> ids = new List<tinyClass(); ids.Add(new tinyClass(1, 2)); bool b = ids.IndexOf(new tinyClass(1, 2))
List comprehensions can be useful in certain situations, but they can also be rather
List<SelectListItem> items = new List<SelectListItem>(); if (a) { SelectListItem deliveryItem = new SelectListItem() {
List<CertMail> lsRecipetNumber = new List<CertMail>(); CertMail class is in data access layer which returns
List<MyClass> myclassList = (List<MyClass>) rs.get(); TreeSet<MyClass> myclassSet = new TreeSet<MyClass>(myclassList); I don't understand why
List<Foo> fooList = Session[foo] as List<Foo>; fooList.Add(bar); Does the call to Add() change the

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.