Title: Using PHP to loop through XML nodes
Last modified: August 31, 2016

---

# Using PHP to loop through XML nodes

 *  Resolved [aarondurber](https://wordpress.org/support/users/aarondurber/)
 * (@aarondurber)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/using-php-to-loop-through-xml-nodes/)
 * I am using an expert agent XML feed to populate a clients estate agent website.
 * Below is a snap shot of the nodes. I wish to loop through the rooms node using
   PHP to display the room name, then the size, then the description. Is there an
   easy way/simple solution to accomplish this within PHP?
 *     ```
       <property reference="xxxxx">
           <main_advert></main_advert>
           <street>Kenilworth Walk</street>
           <brochure>xxxxx</brochure>
           <property_type>House</property_type>
           <rooms>
             <room name="Entrance hall">
               <measurement_text/>
               <description>
                 with radiator, carpet.
               </description>
             </room>
             <room name="Separate WC">
               <measurement_text/>
               <description>
                 with low level WC, hand basin, double glazed UPVC window, radiator, carpet.
               </description>
             </room>
             <room name="Lounge">
               <measurement_text>
                 13' 10'' x 15' 8'' (4.21m x 4.77m)
               </measurement_text>
               <description>
                 with double glazed UPVC french doors and windows to garden,      carpet, two radiators.
               </description>
             </room>
           </rooms>
       </property>
       ```
   
 * I need to query the rooms node (as above) each room has a size and description
   node. i would like to display this data on a wordpress post page. i can pull 
   individual node details and sub nodes using code i found with google search.
 *     ```
       <?php if(get_post_meta($post->ID, 'entrance_hall_name', true) || // this is what i have named the node for room name
       get_post_meta($post->ID, 'entrance_hall_desc', true) || // this is what i have named the node for room description
       get_post_meta($post->ID, 'entrance_hall_size', true) || // this is what i have named the node for room size
       ): ?>
   
       <?php if(get_post_meta($post->ID, 'entrance_hall_name', true)): ?>
       <b><?php echo get_post_meta($post->ID, 'entrance_hall_name', true); ?></b>
       <br>
       <?php if(get_post_meta($post->ID, 'entrance_hall_desc', true)): ?>
       <?php echo get_post_meta($post->ID, 'entrance_hall_desc', true); ?>
       <?php endif; ?>
       <br><br>
       <?php if(get_post_meta($post->ID, 'entrance_hall_size', true)): ?>
       <?php echo get_post_meta($post->ID, 'entrance_hall_size', true); ?>
       <? php echo "<br><br>"; ?>
       <?php endif; ?>
       <?php endif; ?>
   
       <?php if(get_post_meta($post->ID, 'sep_wc_name', true)): ?>
       <?php echo get_post_meta($post->ID, 'sep_wc_name', true); ?>
       <?php endif; ?>
       <br><br>
       <?php endif; ?>
       ```
   
 * I want to loop through the rooms node returning the values for those that are
   there, not all rooms have a size
 * all help appreciated.
 * [https://wordpress.org/plugins/wp-all-import/](https://wordpress.org/plugins/wp-all-import/)

The topic ‘Using PHP to loop through XML nodes’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [xml](https://wordpress.org/support/topic-tag/xml/)

 * 0 replies
 * 1 participant
 * Last reply from: [aarondurber](https://wordpress.org/support/users/aarondurber/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/using-php-to-loop-through-xml-nodes/)
 * Status: resolved