简体   繁体   English

XML / PHP:使用PHP创建XML文本

[英]XML / PHP : Creation of a XML text with PHP

I'm a beginner with XML on PHP. 我是PHP上XML的初学者。 My page returns me the following PHP error: 我的页面向我返回以下PHP错误: 第1列第2行出现错误:文档末尾的多余内容

But, at line 2, there only is a "require_once", followed by 3 others "require_once", the path to the required file is ok, and it ends with a ';'. 但是,在第2行,只有一个“ require_once”,后跟其他3个“ require_once”,所需文件的路径正常,并且以“;”结尾。 The line above is the " 上面的行是“

I have this sample of code, which I think is the source of this error (in this order) 我有此代码示例,我认为是此错误的来源(按此顺序)

$xml = simplexml_load_string("<result/>");
$entitlements = $xml->addChild("entitlements");
$entitlements->addChild("productId", $productId);

then, below : 然后,在下面:

$fulfillmentXML = new SimpleXMLElement($result);
//some stuff with $fullfillmentXML 
echo $xml->asXML();

I do not understand exactly how the XML works in PHP, but I thought there was a problem creating a SimpleXMLElement() after the simplexml_load_string() call. 我不完全了解XML在PHP中的工作方式,但是我认为在simplexml_load_string()调用之后创建SimpleXMLElement()时出现问题。

Your error doesn't look like a PHP error, but rather a browser error generated when it tried to parse the supplied XML contents. 您的错误看起来不像PHP错误,而是尝试解析提供的XML内容时生成的浏览器错误。 Therefore line 2 of the error does not refer to line 2 of your PHP file, but to line 2 of your generated output. 因此,错误的第2行不引用PHP文件的第2行,而是引用生成的输出的第2行。

Check your output (source of your generated page), and see what line 2 is there. 检查您的输出(所生成页面的源),并查看第2行。 Make sure you only have 1 root element, and that nothing comes after it. 确保只有1个根元素,并且之后没有任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM