'Generating XML code from PHP: Missing Title Tag (Again)

So dang close!!!!

Using the DOMDocument method and createElement function, my php code is generating an (almost) working XML output. There are 5 values being displayed: Title, Link, Category, Region, and Date. The latter four work fine, but title doesn't display. Category and Region are short, single words. Date is typical 10 characters. Link is a full HTTP URL. Title text (hdlinestr) can be long, depends on who write the original news headline, but generally the URL is as long or longer.

Here is the code:

$myrss = "(Database name)";

$result=mysqli_query($con, "Select * from rss limit 3");
if($result>0){

$xml = new DOMDocument("1.0");
 
// It will format the output in xml format otherwise
// the output will be in a single row
$xml->formatOutput=true;
$myrss=$xml->createElement("channel");
$xml->appendChild($myrss);
while($row=mysqli_fetch_array($result)){
    
    $block=$xml->createElement("item");
    $myrss->appendChild($block);
        
   
        $hdline=$xml->createElement("title", $row['$hdlinestr']);
        $block->appendChild($hdline);
         
        $urlstr=$xml->createElement("link", $row['urlstr']);
        $block->appendChild($urlstr);
        
        $category=$xml->createElement("category", $row['category']);
        $block->appendChild($category);
        
        $region=$xml->createElement("region", $row['region']);
        $block->appendChild($region);
        
        $pubdate=$xml->createElement("date", $row['pubdate']);
        $block->appendChild($pubdate);
    
}
echo "<xmp>".$xml->saveXML()."</xmp>";
$xml->save("report.xml");
}
else{
    echo "error";
}
}
?>

The result is a nicely formatted report.xml, except that the title, both the start title tag and the actual headline is missing. Here is result:

Atom display of XML code



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source