开发者

Why xml2array() function failing to convert my nested non-well-formed XML file? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about programming within the scope defined in the help center.

Closed 9 years ago.

Improve this question

Using php, i am trying to convert bellow xml file into array. But xml2array() function failing to convert all xml data into array. What is the reason and how to convert this bellow xml into array.

  <?xml version="1.0" encoding="UTF-8"?>
    <OTA_HotelAvailRS Version="1.0">
      <Success Id="141579"/>
        <Properties>
           <Property HotelCityCode="ELS" HotelCode="15534" HotelName="Premier Hotel Regent - Demo">
           <RelativePosition Direction="" Distance="0" DistanceUnitName=""/>
           <EssentialInfo>
           </EssentialInfo>
           <RoomStays>
                <RoomStay>
                     <RatePlans>
                          <RatePlan RatePlanCode="40590"/>
                     </RatePlans>
                     <RoomRates>
                          <RoomRate>
                               <Rates>
                                    <Rate EffectiveDate="2011-10-14" ExpireDate="2011-10-15">
                                         <Base Amount="114.00" CurrencyCode="EUR"/>
                                         <RateDescription Adults="1" Availability="A" Children="0" RoomNum="1">                                                  Standard
                                         </RateDescription>
                                    </Rate>
                               </Rates>
                          </RoomRate>
                     </RoomRates>
                     <Meals Description="Breakfast Buffet" MealType="Breakfast"/>
                </RoomStay>
           </RoomStays>
           <Promotions/>
           <AdditionalInfo>
                <HotelStarDetail rating="3"/>
                <HotelImages>
                     <HotelImage Type="" URL="http://image1.urlforimages.com/1204258/Premier-Hotel-Regent_guest.jpg"/>

                </HotelImages>
                <HotelDescription>
                     <LongDescription> General Description: Beachfront accommodations Location: Conveniently located in the river port city of East London  Located close to shopping area  Perfectly located in beautiful Esplanade overlooking the Indian Ocean Local Attractions: Close to local attractions such as John Gately House, The Hood Point Lighthouse, East London Museum  Nearby outdoor sport activities  Restaurants &amp;amp;&amp;#186;  Lounges: Onsite restaurant Services: 24 hr front desk service  Room service  Valet dry cleaning and laundry services  Shuttle service is available  Meeting Facilities:  Conference rooms hosting up to 800 people  Convention facilities   Small conference room available  Event facilities   Fully equipped business center  Accommodation: Luxury guest rooms  175 guestrooms</LongDescription>

                </HotelDescription>
           </AdditionalInfo>
      </Property>
      <Property HotelCityCode="ELS" HotelCode="15533" HotelName="Mpongo Private Game Reserve - Demo">
           <RelativePosition Direction="" Distance="0" DistanceUnitName=""/>
           <EssentialInfo>
           </EssentialInfo>
           <RoomStays>
                <RoomStay>
                     <RatePlans>
                          <RatePlan RatePlanCode="40589"/>
                     </RatePlans>
                     <RoomRates>
                          <RoomRate>
                               <Rates>
                                    <Rate EffectiveDate="2011-10-14" ExpireDate="2011-10-15">
                                         <Base Amount="174.00" CurrencyCode="EUR"/>
                                         <RateDescription Adults="1" Availability="A" Children="0" RoomNum="1">

                                              River Lodge
                                         </RateDescription>
                                    </Rate>
                               </Rates>
                          </RoomRate>
                     </RoomRates>
                     <Meals Description="Half board" MealType="HalfBoard"/>
                </RoomStay>
                <RoomStay>
                     <RatePlans>
                          <RatePlan RatePlanCode="40588"/>
                     &l开发者_高级运维t;/RatePlans>
                     <RoomRates>
                          <RoomRate>
                               <Rates>
                                    <Rate EffectiveDate="2011-10-14" ExpireDate="2011-10-15">
                                         <Base Amount="117.00" CurrencyCode="EUR"/>
                                         <RateDescription Adults="1" Availability="A" Children="0" RoomNum="1">

                                              Standard
                                         </RateDescription>
                                    </Rate>
                               </Rates>
                          </RoomRate>
                     </RoomRates>
                     <Meals Description="Half board" MealType="HalfBoard"/>
                </RoomStay>
           </RoomStays>
           <Promotions/>
           <AdditionalInfo>
                <HotelStarDetail rating="4"/>
                <HotelImages>
                     <HotelImage Type="" URL="http://image1.urlforimages.com/1204253/Mpongo-Private_guest.jpg"/>
                </HotelImages>
                <HotelDescription>
                     <LongDescription> General Description: Close proximity to major attractions Location: Located in the heart of Eastern Cape at Mpongo  Shopping area is just minutes away Local Attractions: Nearby outdoor sport activities   Close to local attractions such as 2 ? to 3 hour open vehicle game drive, bringing them close to lions, impala, zebra, giraffes, elephants and several smaller animal species Recreation: Outdoor swimming pool Restaurants &amp;amp;&amp;#186;  Lounges: Onsite restaurant Services: Valet dry cleaning and laundry services Meeting Facilities:  Banquet facilities   Wedding venue available Accommodation: 18 guestrooms</LongDescription>

                </HotelDescription>
           </AdditionalInfo>
      </Property>
      <Property HotelCityCode="ELS" HotelCode="15532" HotelName="GARDEN COURT EAST LONDON">
           <RelativePosition Direction="" Distance="" DistanceUnitName=""/>
           <EssentialInfo>
           </EssentialInfo>
           <RoomStays>
                <RoomStay>

                     <RatePlans>
                          <RatePlan RatePlanCode="40586"/>
                     </RatePlans>
                     <RoomRates>
                          <RoomRate>
                               <Rates>
                                    <Rate EffectiveDate="2011-10-14" ExpireDate="2011-10-15">
                                         <Base Amount="162.00" CurrencyCode="EUR"/>
                                         <RateDescription Adults="1" Availability="R" Children="0" RoomNum="1">

                                              Twin for sole use (Standard)
                                         </RateDescription>
                                    </Rate>
                               </Rates>
                          </RoomRate>
                     </RoomRates>
                     <Meals Description="Full breakfast" MealType="Breakfast"/>
                </RoomStay>
                <RoomStay>
                     <RatePlans>
                          <RatePlan RatePlanCode="40587"/>
                     </RatePlans>
                     <RoomRates>
                          <RoomRate>
                               <Rates>
                                    <Rate EffectiveDate="2011-10-14" ExpireDate="2011-10-15">
                                         <Base Amount="162.00" CurrencyCode="EUR"/>
                                         <RateDescription Adults="1" Availability="R" Children="0" RoomNum="1">

                                              Single (Standard)
                                         </RateDescription>
                                    </Rate>
                               </Rates>
                          </RoomRate>
                     </RoomRates>
                     <Meals Description="Full breakfast" MealType="Breakfast"/>
                </RoomStay>
           </RoomStays>
           <Promotions/>
           <AdditionalInfo>
                <HotelStarDetail rating="3"/>
                <HotelFacilities>
                     <Facility Code="*AC" Description="Air conditioning" Name="RoomFacility"/>

                     <Facility Code="*EC" Description="Earliest check-in at 12:00" Name="HotelFacility"/>

                     <Facility Code="*GY" Description="Gymnasium" Name="HotelFacility"/>

                     <Facility Code="*HD" Description="Hairdryer" Name="RoomFacility"/>

                     <Facility Code="*OP" Description="1 outdoor pool (heated)" Name="HotelFacility"/>


                     <Facility Code="*RS" Description="Room Service from  8:00 to 23:30" Name="HotelFacility"/>

                     <Facility Code="*TV" Description="Television" Name="RoomFacility"/>

                </HotelFacilities>
                <HotelImages>
                     <HotelImage Type="Bar/Lounge" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-11.jpg"/>

                     <HotelImage Type="Lobby" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-8.jpg"/>

                     <HotelImage Type="Exterior" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-1.jpg"/>

                     <HotelImage Type="Recreational Facilities" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-12.jpg"/>

                     <HotelImage Type="Guest Room" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-9.jpg"/>


                     <HotelImage Type="Restaurant" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-10.jpg"/>

                     <HotelImage Type="Swimming Pool" URL="http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-3.jpg"/>

                </HotelImages>
                <HotelDescription>
                     <LongDescription>&lt;b&gt;LOCATION&lt;/b&gt;&lt;br&gt;Located on the city's Eastern Beach Promenade the hotel is 20kms from East London airport.  For holidaymakers, the beach is in close proximity and several landmarks and attractions are also not far away from the Garden Court East London such as the Aquarium and the popular Whale Watchers Deck, the famous Nahoon Beach and Gately House museum.&lt;br&gt;&lt;br&gt;&lt;b&gt;ROOMS&lt;/b&gt;&lt;br&gt;The 173 rooms  are slick and modern in design with good size comfortable beds.  All are en suite and offer remote controlled TV and a host of satellite channels, in ,room dining service between 18h30 and 22h00 daily and individually controlled air conditioning all part of the facilities to make you feel welcome and relaxed. Smoking and wheelchair accessible rooms are available on request.&lt;br&gt;&lt;br&gt;&lt;b&gt;RESTAURANT&lt;/b&gt;&lt;br&gt;The Ubuntu restaurant at Garden Court East London offers a buffet breakfast daily, as well as a carvery buffet every evening.  The Brassiere offers a coffee shop menu with light meals.&lt;br&gt;&lt;br&gt;&lt;b&gt;EXTERIOR&lt;/b&gt;&lt;br&gt;A six storey modern building with balconies dominating the facade.&lt;br&gt;&lt;br&gt;&lt;b&gt;LOBBY&lt;/b&gt;&lt;br&gt;A welcoming entrance with seating area for guests and a reception desk&lt;br&gt;&lt;br&gt;&lt;b&gt;GENERAL&lt;/b&gt;&lt;br&gt;The hotel has excellent conferencing facilities as well as a business centre and there is Wifi available for a fee in all rooms as well as public areas.
                     There is also a small gym which is free for guests to use as well as a big outdoor swimming pool with sun loungers.&lt;br&gt;&lt;br&gt;</LongDescription>

                </HotelDescription>
           </AdditionalInfo>
        </Property>          
     </Properties>
   </OTA_HotelAvailRS>


That's because your xml is incorrectly formatted. I see that tag OTA_HotelAvailRS isn't closed.

You can try save it in test.xml file and open in IE. You will see the reason. When your xml will be opened correctly in browser - you can use it with your xml2array function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜