# SimpleXMLElement - how to format output of XML result

**URL:** <https://forum.kirupa.com/t/simplexmlelement-how-to-format-output-of-xml-result/317608>\
**Category:** programming\
**Created:** [December 27, 2010, 3:28pm UTC](https://forum.kirupa.com/t/simplexmlelement-how-to-format-output-of-xml-result/317608 "2010-12-27T15:28:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubenDoliveira](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rubendoliveira/32/3905_2.png) [@RubenDoliveira](https://forum.kirupa.com/u/RubenDoliveira)\
**Post date:** [December 27, 2010, 3:28pm UTC](https://forum.kirupa.com/t/simplexmlelement-how-to-format-output-of-xml-result/317608/1 "2010-12-27T15:28:37Z")

</div>

Hi everyone,

I have data in a database and I’m getting that data and transforming it in XML with PHP. Everything works so far, however, I need to format the output result.

At this point, the elements from the database get all together in the same line, I need to separate each row in a new line… making it pretty and easy to read.

This is my code:

```auto

<?php
	$sxe = new SimpleXMLElement('<bookstore/>');
				
	include ("connection.php");
				
	$myquery = 'SELECT * FROM bookstoretb';
	$sql = mysql_query($myquery);
		if (!$sql)
		{
			error_log("Query $myquery failed: " . mysql_error());
		}
				
	while ( $row = mysql_fetch_array($sql, MYSQL_ASSOC) ) {
		$line = $sxe->addChild('book');
					 
		foreach ( $row as $fieldName => $value)
			$line->addChild($fieldName, $value. " 
 ");
						
	}
	echo $sxe->asXML();
?>

```

Thank you in advance and wishes of a good year!
