Question

Following is the soap xml

i want get the bottom level value how to fetch the value.

<CXMLDocument 0x6e560e0 [0x6874070]> <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <SearchPropertiesResult xmlns="http://www.somdata.com/">
      <ResponseCode>0</ResponseCode>
      <Properties>
        <Property xsi:type="ApartmentBuilding">
          <PropertyData>
            <Id>5684</Id>
            <Bedrooms>0</Bedrooms>
            <Bathrooms>0</Bathrooms>
            <ParentPropertyId>0</ParentPropertyId>
            <ClientId>99</ClientId>
            <Longitude>48.090290069580078</Longitude>
            <Latitude>29.335382461547852</Latitude>
            <MonthlyPaymentFrequency>1</MonthlyPaymentFrequency>
            <PropertyTitle>Sea view, 2 bdr furnished apt</PropertyTitle>
            <PropertyDescription>Nice, sea view,close to Sultan center, 2 bedrooms fully furnished apartment, 1 bathroom,kitchen, living room, swimming pool, balcony, shaded car park, DSL Internet. Rent KD 450/month. Pls call Horizon Real Estate, Mrs Agnieshka on 94916688</PropertyDescription>
            <AdditionalAmenities/>
            <SaleType>Rent</SaleType>
            <Furnishing>Furshished</Furnishing>
            <PropertyType>ApartmentBuilding</PropertyType>
            <Address>
              <Street/>
              <BuildingNumber/>
              <BuildingName/>
              <Area>Salmiya</Area>
              <Region>Hawally</Region>
              <AreaId>17741</AreaId>
              <RegionId>17714</RegionId>
            </Address>
            <Amenities/>
            <Commission>
              <Commission>50</Commission>
              <MonthsRent>1</MonthsRent>
            </Commission>
            <LastListedDate>2011-05-27T14:07:00</LastListedDate>
            <ExpiryDate>2012-05-26T14:07:00</ExpiryDate>
            <Files>
              <sourceData>
                <MimeType>image/jpeg</MimeType>
                <Id>4207</Id>
                <CategoryId>1</CategoryId>
                <PropertyId>5684</PropertyId>
                <FileSize>17076</FileSize>
                <LastModified>2011-05-27T14:01:31.49</LastModified>
                <Position>0</Position>
                <Path>http://www. sourceData.com/staging/newversion/getfile.ashx?property_id=5684&amp;file_id=4207</Path>
                <FileDescription>
                  <Id>1</Id>
                  <Description>View</Description>
                </FileDescription>
                <Thumbnail>
                  <MimeType>image/jpeg</MimeType>
                  <Id>4087</Id>
                  <CategoryId>1</CategoryId>
                  <PropertyId>5684</PropertyId>
                  <FileSize>0</FileSize>
                  <LastModified>2012-03-22T11:24:51.427669+00:00</LastModified>
                  <Position>0</Position>
                  <Path>http://www. sourceData.com/staging/newversion/getfile.ashx?property_id=5684&amp;file_id=4207&amp;thumbnail=true</Path>
                  <FileDescription xsi:type="NullFileDescription">
                    <Id>0</Id>
                  </FileDescription>
                  <Thumbnail xsi:type="NullFile">
                    <Id>0</Id>
                    <CategoryId>0</CategoryId>
                    <PropertyId>0</PropertyId>
                    <FileSize>0</FileSize>
                    <LastModified>2012-03-22T09:10:01.4140542+00:00</LastModified>
                    <Position>0</Position>
                    <Path/>
                    <FileDescription xsi:type="NullFileDescription">
                      <Id>0</Id>
                    </FileDescription>
                  </Thumbnail>
                </Thumbnail>
              </sourceData>
            </Files>
            <VacantUnitAmenities/>
          </PropertyData>
          <PriceRange>700 KD</PriceRange>
          <AreaRange>240m²</AreaRange>
        </Property>
        </Properties>
    </SearchPropertiesResult>
  </soap:Body>
</soap:Envelope>

Problems -How to fetch the value into the dictionary or the array for the particular bottom tag which describe below

-Properties
   -Property
     -PropertyData
        -Files
           -sourceData
                -Path

I want to fetch to the value of the path so please help to solve my problem

problem

I short how to n level soap xml to parse

Thanks in advance for spend your valueable time on my proble

Was it helpful?

Solution 2

At the end i found the solution of that problem

Following two method is use for the bottom level of parsing

- (NSMutableArray *)getAllItems:(NSString *)xpath fileName:(NSString *)file{
    NSMutableArray *res = [[NSMutableArray alloc] init];
    NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:file];
    NSData *XMLData   = [NSData dataWithContentsOfFile:XMLPath];
    CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
    NSArray *nodes = NULL;
    nodes = [doc nodesForXPath:xpath error:nil];

    for (CXMLElement *node in nodes) {
        NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
        int counter;
        for(counter = 0; counter < [node childCount]; counter++) {
            //ignore whitespcae
            NSString * value = [[[node childAtIndex:counter] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            if ([value length] != 0)
                //  common procedure: dictionary with keys/values from XML node
                [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
        }

        [res addObject:item];
        [item release];
    }
    return res;
}
-(void)getNodes{
    NSArray *currencyList = [self getAllItems:@"//sourceData" fileName:@"untitled.xml"];
    NSLog(@"%@",currencyList);
    int numberOfCurrencies = [currencyList count];

    NSArray *name, *symbol;
    NSMutableArray *arForData;
    if (numberOfCurrencies > 0) {
        for (int i = 0; i < numberOfCurrencies; i++) {
            name          = [[currencyList objectAtIndex:i] objectForKey:@"Path"];
            NSLog(@"path is : %@, name);
        }
    }
}

OTHER TIPS

1.Download TouchXML
2.Include it to your project

3.Search for the below method

 CXMLNode *theNode = [[[theClass alloc] initWithLibXMLNode:inLibXMLNode freeOnDealloc:infreeOnDealloc] autorelease];

This method will generate the root node as per the XML tag name

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top