2012-03-28 4 views
0

Hallo, ich entwickle eine Anwendung. Ich bin neu bei den Webdiensten in Android. Ich habe die Antwort vom Server als XML-String bekommen. Ich muss seinen Inhalt analysieren, damit er als Listenansicht angezeigt wird. Wie benutzt man den Sax Parser zum Parsen von XML Strings? Bitte geben Sie einige Codes an. anyhelp geschätzt.Wie analysiere ich die als String gespeicherte Antwort von httppost

Edited: xml Ich habe als String

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

+0

Beitrag einige Code von XML-String. –

Antwort

0

IBM hat ein großes Tutorial veröffentlicht, die im Detail erklärt, wie mit XML (insbesondere einem SAX-Parser) zu arbeiten. Google bietet auch einige großartige Tutorials für ListViews in der ApiDemos. Also, wenn Sie Ihre Modelle mit SAX im Grunde erstellen und sie in einen BaseAdapter für Ihren ListView legen, sollten Sie in Ordnung sein.

Best wishes, Tim

Verwandte Themen