我有这个xml节点
<event id="e20120630204436">
<title>event stop</title>
<source>LiveMass</source>
<channel id="0">
<name>Pax TV</name>
<onclick/>
</channel>
<event_site>
<name/>
<url/>
<onclick/>
</event_site>
<start_date>Sun Jul 01 2012:07/01/2012</start_date>
<start_time>10:00 AM</start_time>
<end_date>Sun Jul 01 2012</end_date>
<end_time>11:00 AM</end_time>
<notes/>
</event>
我检索此节点并想要附加新数据。我用这段代码做到了这一点:
$nodes = $xml->xpath("//event[@id='$nodeid']");
if ( count($nodes) >= 1 ) {
$node = $nodes[0];
}
else {
return;
}
$nodedom = dom_import_simplexml($node);
$dom = $nodedom->ownerDocument;
$xweeks = $dom->createElement("remind_weeks");
$xweeksText = $dom->createTextNode($remind_weeks);
$xweeks->appendChild($xweeksText);
$xsend_remind = $dom->createElement("send_remind");
$xsend_remind->appendChild($xweeks);
$dom->appendChild($xsend_remind);
$savedom = $dom->saveXML();
$xml = new SimpleXMLElement($savedom);
但我得到了这些警告,然后是这一行$xml = new SimpleXMLElement($savedom);
的致命错误。
Warning: SimpleXMLElement::__construct(): Entity: line 233: parser error : Extra content at the end of the document in /Library/WebServer/Documents/Pagelinks_Dev/save_remind.php on line 97
Warning: SimpleXMLElement::__construct(): <send_remind><remind_weeks>11</remind_weeks></send_remind> in /Library/WebServer/Documents/Pagelinks_Dev/save_remind.php on line 97
Warning: SimpleXMLElement::__construct(): ^ in /Library/WebServer/Documents/Pagelinks_Dev/save_remind.php on line 97
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Library/WebServer/Documents/Pagelinks_Dev/save_remind.php:97
我该怎么做才能解决这个错误?