更底层的soap xml解析

时间:2012-03-22 13:27:10

标签: iphone soap xml-parsing touchxml

以下是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级肥皂xml来解析

提前感谢您将有价值的时间花在我的问题上

2 个答案:

答案 0 :(得分:0)

1.下载TouchXML
2.将其包含在您的项目中

3.搜索以下方法

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

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

答案 1 :(得分:-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);
        }
    }
}