如何解析从httppost存储为字符串的响应

时间:2012-03-28 16:02:22

标签: android xml-parsing saxparser

您好我正在开发一个应用程序。我是android新手中的web服务。我得到了作为xml字符串冻结服务器的响应。我需要解析其内容以显示为列表视图。如何使用sax解析器解析xml字符串。请提供一些代码。任何帮助表示赞赏。

编辑:xml我得到了字符串

 <ns2:HotelListResponse xmlns:ns2 = "http://v3.hotel.wsapi.ean.com/">
<customerSessionId>0ABAA871-36B9-A891-3432-83874A39565C</customerSessionId>
<numberOfRoomsRequested>1</numberOfRoomsRequested>
<moreResultsAvailable>true</moreResultsAvailable>
<cacheKey>e36b9a8:134383874a3:5660</cacheKey>
<cacheLocation>10.186.168.113:7303</cacheLocation>
 <cachedSupplierResponse 
    matchedLocale="true" 
    matchedCurrency="true" 
    tpidUsed="5001" 
    otherOverheadTime="5" 
    candidatePreptime="71" 
    supplierResponseTime="9482" 
    supplierResponseNum="20" 
    supplierRequestNum="211" 
    cachedTime="0" />
 <HotelList activePropertyCount = "237" size = "1">
    <HotelSummary ubsScore = "1801" order = "0">
        <hotelId>127092</hotelId>
        <name>The Edgewater - A Noble House Hotel</name>
        <address1>Pier 67, 2411 Alaskan Way</address1>
        <city>Seattle</city>
        <stateProvinceCode>WA</stateProvinceCode>
        <postalCode>98121</postalCode>
        <countryCode>US</countryCode>
        <airportCode>SEA</airportCode>
        <supplierType>E</supplierType>
        <propertyCategory>1</propertyCategory>
        <hotelRating>4.0</hotelRating>
        <confidenceRating>85</confidenceRating>
        <amenityMask>6259019</amenityMask>
        <tripAdvisorRating>4.0</tripAdvisorRating>
        <tripAdvisorReviewCount>590</tripAdvisorReviewCount>
        <tripAdvisorRatingUrl>http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/4.0-12345-4.gif</tripAdvisorRatingUrl>
        <locationDescription>Near Washington State Convention & Trade Center</locationDescription>
        <shortDescription>
            <b>Location.</b>
            <br/>
            The Edgewater - A Noble House Hotel is a business-friendly hotel located in central Seattle, close to Odyssey - The Maritime Discovery Center, Washington State Convention &
        </shortDescription>
        <highRate>249.0</highRate>
        <lowRate>186.75</lowRate>
        <rateCurrencyCode></rateCurrencyCode>
        <latitude>47.61252</latitude>
        <longitude>-122.35013</longitude>
        <proximityDistance>11.898841</proximityDistance>
        <proximityUnit>MI</proximityUnit>
        <hotelInDestination>true</hotelInDestination>
        <thumbNailUrl>/hotels/1000000/20000/11200/11133/11133_73_t.jpg</thumbNailUrl>
        <deepLink>http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=127092&mode=2&numberOfRooms=1&room-0-adult-total=1&room-0-child-total=0&arrivalMonth=8&arrivalDay=3&departureMonth=8&departureDay=4&showInfo=true&locale=en_US&currencyCode=USD</deepLink>
        <RoomRateDetailsList>
            <RoomRateDetails>
                <roomTypeCode>1160</roomTypeCode>
                <rateCode>1221260</rateCode>
                <maxRoomOccupancy>2</maxRoomOccupancy>
                <quotedRoomOccupancy>2</quotedRoomOccupancy>
                <minGuestAge>0</minGuestAge>
                <roomDescription>City Lodge - Nonrefundable</roomDescription>
                <promoId>200803780</promoId>
                <promoDescription>7-Day Advance Purchase Special (Nonrefundable)</promoDescription>
                <currentAllotment>10</currentAllotment>
                <propertyAvailable>true</propertyAvailable>
                <propertyRestricted>false</propertyRestricted>
                <expediaPropertyId>11133</expediaPropertyId>
                <rateKey>c9120acf-4428-4f1d-b6ca-d591651e7d93</rateKey>
                <nonRefundable>true</nonRefundable>
                <RateInfos size = "1">
                    <RateInfo
                        rateChange = "false"
                        promo = "true"
                        priceBreakdown = "true">
                        <RoomGroup>
                            <Room>
                                <numberOfAdults>1</numberOfAdults>
                                <numberOfChildren>0</numberOfChildren>
                            </Room>
                        </RoomGroup>
                        <ChargeableRateInfo
                            commissionableUsdTotal = "186.75"
                            total = "220.87"
                            surchargeTotal = "34.12"
                            nightlyRateTotal = "186.75"
                            averageBaseRate = "249.0"
                            averageRate = "186.75"
                            maxNightlyRate = "186.75"
                            currencyCode = "USD">
                            <NightlyRatesPerRoom size = "1">
                                <NightlyRate
                                    promo = "true"
                                    rate = "186.75"
                                    baseRate = "249.0"/>
                            </NightlyRatesPerRoom>
                            <Surcharges size = "1">
                                <Surcharge amount = "34.12" type = "TaxAndServiceFee"/>
                            </Surcharges>
                        </ChargeableRateInfo>
                        <ConvertedRateInfo
                            total = "220.87"
                            surchargeTotal = "34.12"
                            nightlyRateTotal = "186.75"
                            averageBaseRate = "249.0"
                            averageRate = "186.75"
                            maxNightlyRate = "186.75"
                            currencyCode = "">
                            <NightlyRatesPerRoom size = "1">
                                <NightlyRate
                                    promo = "true"
                                    rate = "186.75"
                                    baseRate = "249.0"/>
                            </NightlyRatesPerRoom>
                            <Surcharges size = "1">
                                <Surcharge amount = "34.12" type = "TaxAndServiceFee"/>
                            </Surcharges>
                        </ConvertedRateInfo>
                    </RateInfo>
                </RateInfos>
            </RoomRateDetails>
        </RoomRateDetailsList>
    </HotelSummary>
</HotelList>

1 个答案:

答案 0 :(得分:0)

IBM发布了一个很棒的Tutorial,它详细解释了如何使用XML(尤其是SAX-Parser)。 Google还为ApiDemos中的ListView提供了一些很棒的教程。因此,如果您基本上使用SAX创建模型并将它们放入ListView的BaseAdapter中,那么您应该没问题。

祝福, 添