xml adding problem
Posted: Tue Jul 21, 2009 7:52 am
hello everyone. I have the following code which fails due to the url present in one of the elements of xml
The output of the above code is
Can someone help me out with this problem please. Again i have a question that if i were to use DOM classes for the same, will that have helped in reducing the code as well as the error that i have now??
Code: Select all
ini_set('display_errors',1);
$update_node = '<advtupdate file="3f3820448fb626c4.xml" action="UPDATE">
<advertisement id="4" type="product">
<name>Flex Black</name>
<type>Utility set</type>
<features>1 1/2 In. flex bladeHigh carbon steel bladeGuaranteed foreverMade in the U.S.A.</features>
<description>Guaranteed Forever. High carbon steel blade individually ground, polished, mirror finished and clear coated. Full tang blade construction. Nylon projection interlock handle resists most paint thinners and solvents. Blade measures 1 1/2 in. wide.</description>
<manufacturer>Hyde Tools</manufacturer>
<size>NA</size>
<url>http://www.homedepot.com/webapp/wcs/stores/servlet/ProductDisplay?storeId=10051&category=something</url>
<image>http://www.homedepot.com/catalog/productImages/300/a7/a7eda673-1283-4539-ba7c-03c1a9dcac94_300.jpg</image>
<extra_info>
<price>$15.97</price>
<site_icon>http://www.homedepot.com/webapp/wcs/stores/servlet/ProductDisplay?storeId=10051&category=something</site_icon>
</extra_info>
</advertisement>
</advtupdate>';
if(!$advt_node = simplexml_load_string($update_node))//$_POST['updateNode']))
{
//$response=create_error_message(3);//error 3;
//print($response);
echo "Something wrong with loading";
exit();
}
else
{
echo "Loaded successfully";
//add the node to xml properly
$file_root_node = simplexml_load_file('3f3820448fb626c4.xml');
// echo $advt_node->asXML();
//add the annotation first
$l_annot = $file_root_node->addChild($advt_node->getName());
//add all the attributes of the annotation parameter
foreach($advt_node->attributes() as $annname=>$annval)
{
$l_annot->addAttribute($annname,$annval);
}
//add children of annotation
foreach($advt_node->children() as $annotchild)
{
//first add the child to the parent node
//$l_annotchild= $l_annot->addChild($annotchild->getName());
$l_annotchild= $l_annot->addChild($annotchild->getName(),$annotchild);
//now loop through the subchildren and add them also
foreach($annotchild->children() as $annotsubchild)
{
$l_annotchild->addChild($annotsubchild->getName(),$annotsubchild);
}
}
if(!$file_root_node->asXML('3f3820448fb626c4.xml'))
{
echo "problem saving the file";
}
}
Code: Select all
Loaded successfully
Warning: SimpleXMLElement::addChild() [function.SimpleXMLElement-addChild]: unterminated entity reference category=something in D:\Dev\Apache Software Foundation\Apache2.2\htdocs\dummyproject\xmlnode_httpproblem.php on line 52