# Fwrite xml file with attributes

**URL:** <https://forum.kirupa.com/t/fwrite-xml-file-with-attributes/180904>\
**Category:** Uncategorized\
**Created:** [March 4, 2006, 2:11pm UTC](https://forum.kirupa.com/t/fwrite-xml-file-with-attributes/180904 "2006-03-04T14:11:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyde](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@hyde](https://forum.kirupa.com/u/hyde)\
**Post date:** [March 4, 2006, 2:11pm UTC](https://forum.kirupa.com/t/fwrite-xml-file-with-attributes/180904/1 "2006-03-04T14:11:43Z")

</div>

Hi,

I am looking for a way to write an xml with attributes like this :

\<announcements\>  
\<news title=“Groove Magazine#98/N7 CD” date=“2006” image=“images/news/groovethumb.jpg” hoes=“images/news/groove.jpg” aside=“if.mp3” buy=“not for sale”\>  
\<copy\>  
\<p\>  
Compilation with various artists like Henrik Schwarz, I:Cube, Steve Spacek a.o  
\</p\>  
\</copy\>  
\</news\>

I now have this script, but that generates an xml my flash file cannot read. The script is :

\<?php

header(“Content-type: text/xml”);

$host = “localhost”;  
$user = “joomla108”;  
$pass = “\*\*\*\*\*\*l”;  
$database = “joomla108”;

$linkID = mysql\_connect($host, $user, $pass) or die(“Could not connect to host.”);  
mysql\_select\_db($database, $linkID) or die(“Could not find database.”);

//$query = “SELECT \* FROM jos\_content ORDER BY created DESC”;  
$query = “SELECT \* FROM jos\_content WHERE sectionid=‘1’ ORDER BY sectionid DESC”;  
$resultID = mysql\_query($query, $linkID) or die(“Data not found.”);

$xml\_output = "\<?xml version=“1.0”?\>  
";  
$xml\_output .= "\<announcements\>  
";

for($x = 0 ; $x \< mysql\_num\_rows($resultID) ; $x++){  
$row = mysql\_fetch\_assoc($resultID);  
$xml\_output .= " \<news\>  
“;  
$xml\_output .= " \<date\>” . $row[‘created’] . "\</date\>  
“;  
$xml\_output .= " \<title\>” . $row[‘title’] . "\</title\>  
“;  
$xml\_output .= " \<intro\>” . $row[‘introtext’] . "\</intro\>  
“;  
$xml\_output .= " \<full\>” . $row[‘fulltext’] . "\</full\>  
";  
$xml\_output .= " \</news\>  
";  
}

$xml\_output .= “\</announcements\>”;

echo $xml\_output;

$printout = fopen(‘main.xml’,‘w’);  
fwrite($printout,$xml\_output);  
fclose($printout);  
//mail($from, $subject, $klantbericht, $additionalHeaders);

?\>

The above php code generates an xml without attributes but with childes. Anybody an idea how to get php to write attributes instead of childs ?

Thx in advance !

Bart
