Search code examples
phpjsonxmlxmlserializer

convert xml to array in php + xml nodes


How to convert xml to array in php, how to manipulate the nodes that are inside RoomList. Any suggestions on how I can do this?

       <UREFHotelesTarifas xmlns="http://zafiro.tse.com">
         <Token>10956C8E-E312-4E48-A7BD-09FEB99EEBFD</Token>
        <Preset>xx</Preset>
        <HotelIDLIst>1959,-1</HotelIDLIst>
        <FechaDesde>2017-12-17</FechaDesde>
        <FechaHasta>2017-12-20</FechaHasta>
       <RoomList>
         <Root xmlns="http://test.sytes.net">
            <RoomInfo>
               <AdultNum>2</AdultNum>
              <ChildNum>1</ChildNum>
              <ns1:ChildAges age="2"/>
           </RoomInfo>
        </Root>
     </RoomList>
     <Cupo>1</Cupo>
  </UREFHotelesTarifas>

Solution

  • $xml = simplexml_load_string($xmlString);
    $array = json_decode(json_encode((array) $xml), 1);