2012-03-22 93 views
-1

以下是肥皂xml更多底层soap 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级SOAP XML解析

预先感谢您花时间居停在我的proble

回答

-1

最后,我发现该问题的解决方案

以下两种方法用于底层解析

- (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到您的项目

3.Search为以下方法

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

这方法将根据XML标记名称生成根节点