Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Αναγνωση xml

Îåêßíçóå áðü ôï ìÝëïò evagelos. Τελευταία δημοσίευση από το μέλος Stratos54248 στις 02-02-2015, 10:40. Υπάρχουν 3 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  13-12-2014, 20:48 76024

    Αναγνωση xml

    Γεια σας παιδια,

    επειδή ΔΕΝ το εχω (και) με την αναγνωση XML αρχείου.

    Θέλω να διαβασω το RoomType απο το αρχείο καθώς και τις υπολοιπες πληροφορίες.

    Τι πρέπει να γραψω;

    Μεχρι στιγμής είμαι εδω:

    XmlDocument doc = new XmlDocument();
    doc.Load("responce.xml");
    XmlNodeList infos = doc.GetElementsByTagName("HotelReservationInfo");   //η loop μας!!!
    foreach (XmlElement infElem in infos)
    {

    }

     

     

    <?xml version="1.0" encoding="UTF-8"?>
    <AgentReservationListRS Target="Production" Version="1.000" TimeStamp="2014-12-13T19:58:16+02:00" EchoToken="chris" xmlns="http://www.opentravel.org/OTA/2003/05">
      <BuyerReservations>
        <BuyerInfo BusinessID="AHDaaaweb" Name="AAA Web Travel LTD. - Irini Velonaki" ContractType="B2B_TYPE" Address="46, Amalias Ave." City="Athens" PostCode="105 58" Country="GR" Phone="210-9483580" Category="Other" />
        <HotelReservations>
          <HotelReservationInfo>
            <HotelReservation RoomStayReservation="true">
              <RoomStays>
                <RoomStay IndexNumber="1">
                  <RoomTypes>
                    <RoomType RoomTypeCode="00002" NumberOfUnits="1">
                      <RoomDescription>
                        <Text>Double Room</Text>
                        <Text />
                        <Text />
                      </RoomDescription>
                      <Amenities>
                        <Amenity RoomAmenity="3" />
                        <Amenity RoomAmenity="2" />
                      </Amenities>
                    </RoomType>
                  </RoomTypes>
                  <RatePlans>
                    <RatePlan RatePlanType="13.RPT" RatePlanCode="00007" RatePlanName="Greek">
                      <RatePlanDescription>
                        <Text />
                        <Text />
                      </RatePlanDescription>
                    </RatePlan>
                  </RatePlans>
                  <RoomRates>
                    <RoomRate RatePlanCode="00007" RoomTypeCode="00002" NumberOfUnits="1">
                      <Rates>
                        <Rate EffectiveDate="2014-09-27+02:00" ExpireDate="2014-09-28+02:00">
                          <Base AmountBeforeTax="61.22" />
                          <AdditionalGuestAmounts>
                            <AdditionalGuestAmount AgeQualifyingCode="10">
                              <Amount AmountBeforeTax="0.0" />
                            </AdditionalGuestAmount>
                          </AdditionalGuestAmounts>
                          <Fees>
                            <Fee Type="Inclusive" Code="14.MPT" Amount="0.0" />
                          </Fees>
                          <Total AmountBeforeTax="61.22" AmountAfterTax="61.22" CurrencyCode="EUR" />
                        </Rate>
                      </Rates>
                      <Total AmountAfterTax="61.22" />
                    </RoomRate>
                  </RoomRates>
                  <GuestCounts>
                    <GuestCount Count="2" AgeQualifyingCode="10" />
                  </GuestCounts>
                  <TimeSpan Start="2014-09-27" End="2014-09-28+02:00" />
                  <DepositPayments>
                    <GuaranteePayment PaymentCode="8">
                      <AcceptedPayments>
                        <AcceptedPayment>
                          <PaymentCard CardType="1" CardCode="VI" />
                        </AcceptedPayment>
                        <AcceptedPayment>
                          <PaymentCard CardType="1" CardCode="MC" />
                        </AcceptedPayment>
                      </AcceptedPayments>
                      <AmountPercent CurrencyCode="EUR" Amount="61.22" />
                      <Deadline AbsoluteDeadline="2014-09-27T12:00:00" />
                      <Description>
                        <Text>The total amount of your stay must be charged at the time pf the booking</Text>
                      </Description>
                    </GuaranteePayment>
                  </DepositPayments>
                  <CancelPenalties>
                    <CancelPenalty>
                      <Deadline AbsoluteDeadline="2014-09-17T12:00:00.000+03:00" />
                      <AmountPercent TaxInclusive="true" CurrencyCode="EUR" Amount="0.0" Percent="0.0" />
                      <PenaltyDescription>
                        <Text>Please see below cancellation policy</Text>
                      </PenaltyDescription>
                    </CancelPenalty>
                    <CancelPenalty>
                      <Deadline AbsoluteDeadline="2014-09-27T12:00:00.000+03:00" />
                      <AmountPercent TaxInclusive="true" CurrencyCode="EUR" Amount="30.61" Percent="50.0" />
                      <PenaltyDescription>
                        <Text>Please see below cancellation policy</Text>
                      </PenaltyDescription>
                    </CancelPenalty>
                    <CancelPenalty NonRefundable="true">
                      <AmountPercent TaxInclusive="true" CurrencyCode="EUR" Amount="61.22" Percent="100.0" />
                    </CancelPenalty>
                  </CancelPenalties>
                  <Total AmountAfterTax="61.22" CurrencyCode="EUR" />
                  <BasicPropertyInfo HotelCode="AHDAAA00029" HotelName="TITANIA HOTEL">
                    <Address>
                      <AddressLine>Panepistimiou 52 </AddressLine>
                      <CityName>Athens Center</CityName>
                      <PostalCode>106 78</PostalCode>
                      <County>Athens</County>
                      <CountryName Code="GR">Greece</CountryName>
                    </Address>
                    <ContactNumbers>
                      <ContactNumber PhoneNumber="0030-2103326000 " PhoneTechType="1" />
                      <ContactNumber PhoneNumber="0030-2103300700 " PhoneTechType="3" />
                    </ContactNumbers>
                    <Award Provider="PMS" Rating="4" />
                  </BasicPropertyInfo>
                  <TPA_Extensions>
                    <RoomGuests>
                      <RoomGuest title="" firstName="N/A" lastName="N/A" ageQualifyingCode="10" roomNumber="1" />
                      <RoomGuest title="" firstName="N/A" lastName="N/A" ageQualifyingCode="10" roomNumber="1" />
                    </RoomGuests>
                    <RoomStayStatus>ACTIVE</RoomStayStatus>
                    <SellerCommission>1.22</SellerCommission>
                    <BuyerCommission>0.0</BuyerCommission>
                  </TPA_Extensions>
                  <ResGuestRPHs>
                    <ResGuestRPH RPH="1" />
                  </ResGuestRPHs>
                </RoomStay>
              </RoomStays>
              <ResGuests>
                <ResGuest AgeQualifyingCode="10" ResGuestRPH="1">
                  <Profiles>
                    <ProfileInfo>
                      <Profile ProfileType="1">
                        <Customer>
                          <PersonName>
                            <GivenName>George</GivenName>
                            <Surname>Bountounis</Surname>
                          </PersonName>
                          <Email>[email protected]</Email>
                        </Customer>
                        <Affiliations>
                          <TravelArranger Code="AHDaaaweb" />
                        </Affiliations>
                      </Profile>
                    </ProfileInfo>
                  </Profiles>
                </ResGuest>
              </ResGuests>
              <ResGlobalInfo>
                <TimeSpan Start="2014-09-27+03:00" End="2014-09-28+03:00" />
                <Total AmountAfterTax="61.22" CurrencyCode="EUR" />
                <HotelReservationIDs>
                  <HotelReservationID ResID_Type="14" ResID_Value="CONFAHD20140728172510240" ResID_Source="ENTRADA" ResID_SourceContext="Ahead Travel Test" ForGuest="true" ResID_Date="2014-07-28T17:25:10.240+03:00" />
                </HotelReservationIDs>
                <Profiles>
                  <ProfileInfo>
                    <Profile>
                      <CompanyInfo>
                        <CompanyName>Santorini Travel</CompanyName>
                        <AddressInfo>
                          <AddressLine>ATHENS</AddressLine>
                          <CountryName Code="GR">Greece</CountryName>
                        </AddressInfo>
                        <TelephoneInfo PhoneNumber="2109933456, 697245678" />
                        <Email>[email protected]</Email>
                      </CompanyInfo>
                    </Profile>
                  </ProfileInfo>
                </Profiles>
              </ResGlobalInfo>
              <TPA_Extensions>
                <ReservationBuyingPrice totalCost="60.0" fromCurrency="EUR" toCurrency="EUR" exchangeRate="1" />
                <ContractBuyerCreditLimit>483.51</ContractBuyerCreditLimit>
                <ReservationStatus>ACTIVE</ReservationStatus>
                <BuyerID>AHDaaaweb</BuyerID>
              </TPA_Extensions>
            </HotelReservation>
            <AdditionalInfo BuyerCommission="0.0" SellerCommission="1.22">
              <SupplierInfo BusinessID="AHDAAA" Name="Ahead Travel Test" ContractType="B2B_TYPE" Address="46 Amalias Ave" City="Athens" PostCode="10558" Country="GR" Phone="2109483580" />
            </AdditionalInfo>
          </HotelReservationInfo>
         

     

  •  15-12-2014, 01:55 76031 σε απάντηση της 76024

    Απ: Αναγνωση xml

    Καλησπέρα,

    Για να μην μπλέκεις με πολύπλοκες διαδικασίες: για να διαβάσεις το αρχείο, δημιούργησε μια κλάση μέσα από το Visual Studio (Copy τα περιεχόμενα του xml αρχείου στο clipboard και στην συνέχεια, menu Edit/Paste Special/Paste XML as Classes) και χρησιμοποίησε τον παρακάτω κώδικα για να κάνεις de-serialize το αρχείο.

            public static T FromFile(string filePath)

            {

                if (string.IsNullOrEmpty(filePath))

                    throw new ArgumentNullException("filePath");


                T r = null;


                if (File.Exists(filePath))

                {

                    using (StreamReader textReader = File.OpenText(filePath))

                    {

                        using (XmlReader reader = new XmlTextReader(textReader))

                        {

                            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));

                            if (xmlSerializer.CanDeserialize(reader))

                                r = xmlSerializer.Deserialize(reader) as T;

                        }

                    }

                }


                return r;

            }


    * όπου Τ ο τύπος της κλάσης που δημιούργησες στο προηγούμενο βήμα

       

     George J.


    George J. Capnias: Χειροπρακτικός Υπολογιστών, Ύψιστος Γκουράρχης της Κουμπουτερολογίας
    w: capnias.org, t: @gcapnias, l: gr.linkedin.com/in/gcapnias
    dotNETZone.gr News
  •  15-12-2014, 12:50 76033 σε απάντηση της 76024

    Απ: Αναγνωση xml

    Καλημέρα

    Από τότε που βγήκε το LINQ εγώ έχω γίνει θιασώτης και θαυμαστής και ίσως και μερικές φορές το παρακάνω. Μου αρέσει πολύ η λογική του ίσως επειδή έχω database developer background. Δες άπειρα παραδείγματα ψάχνοντας .net  read xml with linq :

    http://www.codearsenal.net/2012/07/c-sharp-load-xml-using-xlinq.html#.VI66-CusXZg 

    http://stackoverflow.com/questions/670563/linq-to-read-xml

    κλπ κλπ κλπ 


    Manos
  •  02-02-2015, 10:40 76425 σε απάντηση της 76033

    Απ: Αναγνωση xml

    Συμφωνώ και εγώ. LINQ Rulez. Ψάξε για XElement και XDocument.

    http://www.dotnetperls.com/xelement

     

Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems