SimpleXMLElement(PHP)在XML根属性上引发错误

SimpleXMLElement(PHP)在XML根属性上引发错误,xml,post,simplexml,php,Xml,Post,Simplexml,Php,我正在从事一个项目,该项目将获取通过表单中的textarea输入提交的XML数据,然后提取数据并将其放入数据库。我的XML根字段中的属性出错(每次都是相同的模式,但值不同)。如果我删除这些属性,效果会很好,但我不希望每次我将数据发送到脚本时都必须删除这些属性 以下是我正在使用的数据和代码示例(给我带来错误的部分): --剪断-- 如果我以这种方式发布数据,则会出现以下错误: Warning: SimpleXMLElement::__construct() [function.SimpleXM

我正在从事一个项目,该项目将获取通过表单中的textarea输入提交的XML数据,然后提取数据并将其放入数据库。我的XML根字段中的属性出错(每次都是相同的模式,但值不同)。如果我删除这些属性,效果会很好,但我不希望每次我将数据发送到脚本时都必须删除这些属性

以下是我正在使用的数据和代码示例(给我带来错误的部分):


--剪断--
如果我以这种方式发布数据,则会出现以下错误:

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : AttValue: " or ' expected in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : attributes construct error in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Couldn't find end of Start Tag raid line 1 in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Extra content at the end of the document in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php:13 Stack trace: #0 /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php(13): SimpleXMLElement->__construct('<raid generated...') #1 {main} thrown in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:实体:第1行:解析器错误:AttValue:“或”应在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中出现
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:^in/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php,第13行
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:实体:第1行:解析器错误:第13行/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中的属性构造错误
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:^in/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php,第13行
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:实体:第1行:解析器错误:在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中找不到开始标记raid第1行的结尾
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:^in/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php,第13行
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:实体:第1行:解析器错误:第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中的文档末尾有额外内容
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:在第13行的/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php中
警告:SimpleXMLElement::u construct()[function.SimpleXMLElement---construct]:^in/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php,第13行

致命错误:在/home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php(13):SimpleXMLElement->(“我怀疑您启用了magic_quote,因此将反斜杠添加到XML中

尽量去掉反斜杠

$xml_d = stripslashes($_POST['h_input']);
<html>
<head>
</head>
<body>
<?php
if(isset($_POST['h_input']))
{
    //echo 
    //$xml_d = file_get_contents('php://input');
    $xml_d = $_POST['h_input'];
    //print_r($xml_d);
    $xml = new SimpleXMLElement($xml_d);

    echo $xml->zone . "<br />";
    foreach ($xml->players->player as $player) {
        echo $player->name . "<br />";
    }
} else {
?>
<form action="headcount.php" method="post" name="headcount">
<textarea rows="10" cols="30" name="h_input">
</textarea>
<input type="submit" />
</form>
</body>
</html>
$xml_d = stripslashes($_POST['h_input']);