2012-03-22 14 views
-1

以下は石鹸のxmlですもっと下のレベルの石鹸xmlの解析

私は値を取得する方法の最下位レベルの値を取得します。

<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> 

問題 辞書や

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

下に記述する特定の底タグの配列に値を取得するために - どのように私はパスの値に取得したいので、に助けてください私は短いどのようにn個

を解析するレベルの石鹸XML

問題

私の問題を解決

以下の方法のためにあなたのプロジェクト

3.Searchに私のproble

答えて

-1

最終的に私はその問題の解決策を見つけました

下位レベルの解析には、次の2つの方法があります。

- (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); 
     } 
    } 
} 
0

1.Download TouchXML
2.Includeでそれをあなたの旅行の一番の時間を過ごすための事前のおかげで

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

このメソッドは、XMLタグ名でルートノードを生成します

関連する問題