Title: Export Images as Nested Elements
Last modified: May 28, 2019

---

# Export Images as Nested Elements

 *  Resolved [Mike](https://wordpress.org/support/users/michael-copestake/)
 * (@michael-copestake)
 * [7 years ago](https://wordpress.org/support/topic/export-images-as-nested-elements/)
 * Hi,
 * I’m creating an XML feed, using the custom XML format, that needs to list images
   like this:
 *     ```
       <images>
       	<image id="1">
       		<url>http://domain.com/imagefile.jpg</url>
       	</image>
       </images>
       ```
   
 * There doesn’t seem to be a way to do this using the XML Editor, so I’ve written
   a custom function which looks like this:
 *     ```
       function image( $url = null) {
       	$i = 1;
       	foreach ( $url as $image ) {
       		$output .= '<image id="' . $i . '"><url>' . $image . '</url\></image>';
       		$i++;
       	}
       	return htmlentities($output);
       }
       ```
   
 * I’ve tried various different things, and it’s always output as text rather than
   XML, so isn’t passing validation.
 * Any help to get this working as needed would be greatly appreciated.
 * Thank you,
    Mike

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years ago](https://wordpress.org/support/topic/export-images-as-nested-elements/#post-11585888)
 * Hey [@michael-copestake](https://wordpress.org/support/users/michael-copestake/)
 * Please try this code instead:
 *     ```
       function image( $url = null) {
       	$i = 1;
       	$output = '';
       	foreach ( $url as $image ) {
       		$output .= '**LT**image id="' . $i . '"**GT**';
       		$output .= '**LT**url**GT**' . $image . '**LT**/url**GT**';
       		$output .= '**LT**/image**GT**';
       		$i++;
       	}
       	return $output;
       }
       ```
   
 * Usage:
 * `<images>[image({Image URL})]</images>`
 *  Thread Starter [Mike](https://wordpress.org/support/users/michael-copestake/)
 * (@michael-copestake)
 * [7 years ago](https://wordpress.org/support/topic/export-images-as-nested-elements/#post-11588626)
 * [@wpallimport](https://wordpress.org/support/users/wpallimport/) thank you!
 * That worked! I had another look through the documentation and couldn’t see it
   anywhere though, perhaps the docs can be updated for WP All Export to be a bit
   more thorough.
 * I appreciate your quick response though, I’ll mark this as resolved now.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 12 months ago](https://wordpress.org/support/topic/export-images-as-nested-elements/#post-11601464)
 * Hey [@michael-copestake](https://wordpress.org/support/users/michael-copestake/)
 * > I had another look through the documentation and couldn’t see it anywhere though,
   > perhaps the docs can be updated for WP All Export to be a bit more thorough.
 * Yes, agreed – this is definitely something we’re working on.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Export Images as Nested Elements’ is closed to new replies.

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

 * 3 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [6 years, 12 months ago](https://wordpress.org/support/topic/export-images-as-nested-elements/#post-11601464)
 * Status: resolved