Using a var as agrument 2 in addChild method for writing XML
Here i parse some data from a webpage.
I want to write it to an file. It all works ok when i use some test strings in
$xml->addChild('alink', 'test');
But when i try and write in the data i actually need to use
$xml->addChild('alink', $value);
It doesnt work.
Message is :
Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]: unterminated entity reference .wvx= in C:\Documents and Settings\Owner\My Documents\Downloads\XAMPP_1.7.1\xampp\htdocs\PhpTest2\index.php on line 96
Complete code. Why does addChild not let me use a var there as agrument 2 in that method? And what is the word around to getting that working. Can find no explanation on php.net
$dom = new DOMDocument();
@$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
$articleList = $xpath->query("//body/div/div/div/table/tbody/tr/td/a");
$xml = new SimpleXmlElement('<links></links>');
$xml->addChild('dvd');
foreach ($articleLis开发者_JAVA百科t as $art)
{
$value = $art->getAttribute('href');
$xml->addChild('alink', $value);
}
$xml->asXML('/simplexml_create.xml');
Many Thanks, -Code
精彩评论