I am not able to add line braks after each node while writing xml file. Xml files are getting write in proper way as i want. but i want to add a line break after completion of every node.
following is my code for xml formation
<?php
//Create Database connection
$mysqli = new mysqli('localhost', 'user', 'pass', 'dbname');
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
}
/* if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
*/
$xml2 = new SimpleXMLElement('<xml/>');
$xml2->addAttribute('encoding','UTF-8');
// $xml2->formatOutput = true;
// $xml2->preserveWhiteSpace = false;
for ($i = 0; $i < 2; $i++) {
$start = $i * 10000;
$query = "select tablecolname from tablename limit $start, 10000";
$result = mysqli_query($mysqli,$query);
//Create SimpleXMLElement object
$xml = new SimpleXMLElement('<node/>');
while($row = mysqli_fetch_array($result)) {
$mydata = $xml->addChild('internalnode');
$mydata = $xml->addChild('\n');
$mydata->loc=$row['Site'];
//htmlentities(strip_tags($mydata->loc=$row['Siteurl']), ENT_COMPAT,'utf-8');
$mydata = $xml->addChild('\n');
}
// used to be: $fp = fopen("folder/file2.xml","wb");
$fp = fopen("site2/sitemap$i.xml","wb");
fwrite($fp,utf8_encode($xml->asXML()));
fclose($fp);
}
$xml = new SimpleXMLElement('<urlset/>');
?>
My current xml file which is getting written is as follows:
<?xml version="1.0">
<node><internalnode>text</internalnode><internalnode>text</internalnode>......</node>
i want the format should be like.
<?xml version="1.0">
<node>
<internalnode>text</internalnode>
<internalnode>text</internalnode>
.
.
.
</node>
Please help in correcting code so that i can add line after each fragment.