XML : Variable value inside XML tag

I want to put the value of $album into an XML tag called category. But everything I try is wrong. The closest I get is the variable name $album but not the data inside. I'm new to writing XML with php. I have tried all sorts of concatenation & have seen CDATA mentioned here but don't know if I should be using it or how.

  <?php  $dbhost = "localhost";  $dbuser = "user";  $dbpass = "password";  $dbname = "db";  @mysql_connect($dbhost,$dbuser,$dbpass);  mysql_select_db($dbname);      $sql = "SELECT * FROM responsivegallery_rgal";  $q   = mysql_query($sql) or die(mysql_error());    $album = $q['album_rgal'];  $category_tag = '"<category caption = ". $album .">"';    $xml = "<gallery>";  while($r = mysql_fetch_array($q)){        $xml .= $category_tag ."</category>";    $xml .= "<item>";     $xml .= "<image>"."gallery_files/slides/".$r['image_rgal']."</image>";    $xml .= "<thumb>"."gallery_files/slides/".$r['thumb_rgal']."</thumb>";      $xml .= "<caption>".$r['title_rgal']."</caption>";    $xml .= "</item>";    }  $xml .= "</gallery>";  $sxe = new SimpleXMLElement($xml);  $sxe->asXML("test.xml");  //$sxe->asXML("../gallery_files/gallery.xml");  ?>    

No comments:

Post a Comment