在php中用dom修改xml文档
Parseerror:syntaxerror,unexpectedT_STRINGinF:\wamp\Apache2.2\htdocs\12.16.phponline11...
Parse error: syntax error, unexpected T_STRING in F:\wamp\Apache2.2\htdocs\12.16.php on line 11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
$xmlfile="sale.xml";
$modfile=AddSale($xmlfile,"1004","洗衣机","2006-10-23","2100","7");
print($modfile);
function AddSale($xml,$ID,$productName,$date,$price,$quantity)
{
$dom=new DOMDocument();
$dom->formatOutput=TRUE;
$dom->load($xml);
$root=$dom->documentElement;
$children = $root->childNodes;
foreach($children as $child)
{
if($child->nodeType==XML_ELEMENT_NODE)
{
if ($child->nodeName=="saleInfo"){
$newsale = $dom->createElement("sale");
$newsale->setAttribute("ID",$ID);
$nname=$dom->createElement("productName");
$nametext=$dom->createTextNode($productName);
$nname->appendChild($nametext);
$ndate=$dom->createElement("date");
$datetext=$dom->createTextNode($date);
$ndate->appendChild($datetext);
$nprice=$dom->createElement("price");
$pricetext=$dom->createTextNode($price);
$nprice->appendChild($pricetext);
$nquantity=$dom->createElement("quantity");
$quantitytext=$dom->createTextNode($quantity);
$nquantity->appendChild($quantitytext);
$newsale->appendChild($nproductname);
$newsale->appendChild($ndate);
$newsale->appendChild($nprice);
$newsale->appendChild($nquantity);
$child->appendChild($newsale);
}
}
}
$xml1=$dom->saveXML();
$dom->save("addnewsale.xml");
return $xml1;
}
?>
</body>
</html> 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
$xmlfile="sale.xml";
$modfile=AddSale($xmlfile,"1004","洗衣机","2006-10-23","2100","7");
print($modfile);
function AddSale($xml,$ID,$productName,$date,$price,$quantity)
{
$dom=new DOMDocument();
$dom->formatOutput=TRUE;
$dom->load($xml);
$root=$dom->documentElement;
$children = $root->childNodes;
foreach($children as $child)
{
if($child->nodeType==XML_ELEMENT_NODE)
{
if ($child->nodeName=="saleInfo"){
$newsale = $dom->createElement("sale");
$newsale->setAttribute("ID",$ID);
$nname=$dom->createElement("productName");
$nametext=$dom->createTextNode($productName);
$nname->appendChild($nametext);
$ndate=$dom->createElement("date");
$datetext=$dom->createTextNode($date);
$ndate->appendChild($datetext);
$nprice=$dom->createElement("price");
$pricetext=$dom->createTextNode($price);
$nprice->appendChild($pricetext);
$nquantity=$dom->createElement("quantity");
$quantitytext=$dom->createTextNode($quantity);
$nquantity->appendChild($quantitytext);
$newsale->appendChild($nproductname);
$newsale->appendChild($ndate);
$newsale->appendChild($nprice);
$newsale->appendChild($nquantity);
$child->appendChild($newsale);
}
}
}
$xml1=$dom->saveXML();
$dom->save("addnewsale.xml");
return $xml1;
}
?>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询