我有一个将对象层次结构转换为xml的php函数。 asXML没有按预期工作。谁能告诉我为什么这样:
$oReportXML = new SimpleXMLElement("<report></report>");
$oReportXML->addChild('details');
$oReportXML->addChild('configuration');
$oReportXML->addChild('datasources');
$oReportXML->addChild('styles');
$oReportXML->addChild('classes');
$oReportXML->addChild('tables');
$oReportXML->details->addChild('author',$this->iAuthor);
$oReportXML->details->addChild('date_created',$this->iDateCreated);
$oReportXML->details->addChild('date_modified',$this->iLastModifiedDate);
$oReportXML->details->addChild('modified_by',$this->iLastModifiedBy);
$oReportXML->details->addChild('id',$this->iReportID);
print_r($this);
print "<p>".$oReportXML->asXML()."</p>";
会输出:
Report Object ( [iAuthor] => 1 [iDateCreated] => 11 [iLastModifiedDate] => 1330435328 [iLastModifiedBy] => 1378 [iReportID] => 0 [sSubject] => sSubject [iCategory] => iCategory [sKeywords] => sKeywords [sDescription] => sDescription [sTitle] => IGNORE_ME [aTables] => Array ( ) [aClasses] => Array ( ) [aDataSources] => Array ( ) [aStyles] => Array ( ) [oParent:private] => )
111133043532813780
答案 0 :(得分:3)
print "<p>".htmlentities ($oReportXML->asXML())."</p>";
我认为如果你查看xml所在的源代码,但是因为你是通过浏览器来查找它,而这些文件恰好是所有标签,你只能看到文本节点。
答案 1 :(得分:0)
如果您在浏览器中查看输出,您将只看到值,因为浏览器不会显示标记。查看源代码,或添加标题('Content-type:text / xml');告诉浏览器它应该显示XML