Php simplexml\u加载\u字符串函数中出错

Php simplexml\u加载\u字符串函数中出错,php,simplexml,Php,Simplexml,我在变量php中有以下字符串 <root> <id></id> <title>Maarch Capture Connector</title> <width>400</width> <height>250</height> <center>true</center> <fields> <node>

我在变量php中有以下字符串

<root>
  <id></id>
  <title>Maarch Capture Connector</title>
  <width>400</width>
  <height>250</height>
  <center>true</center>
  <fields>
    <node>
        <type>comboBox</type>
        <id>ingoing</id>
        <label>Courrier</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>Y</id>
                <label>Arrivée</label>
            </node>
            <node>
                <id>N</id>
                <label>Départ</label>
            </node>
        </values>
        <default_value>Y</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>priority</id>
        <label>Priorité</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>0</id>
                <label>Priorité trés haute</label>
            </node>
            <node>
                <id>1</id>
                <label>Priorité haute</label>
            </node>
            <node>
                <id>2</id>
                <label>Priorité normale</label>
            </node>
            <node>
                <id>3</id>
                <label>Priorité basse</label>
            </node>
        </values>
        <default_value>2</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>services</id>
        <label>Service</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>9</id>
                <label>Compay SEGUNDO</label>
            </node>
            <node>
                <id>10</id>
                <label>Contract 1 for Eric SPRITZ : Life insurance</label>
            </node>
            <node>
                <id>13</id>
                <label>Contract 1 for Thomas BECK : Life insurance</label>
            </node>
            <node>
                <id>11</id>
                <label>Contract 2 for Eric SPRITZ : Home insurance</label>
            </node>
            <node>
                <id>14</id>
                <label>Contract 2 for Thomas BECK : Home insurance</label>
            </node>
            <node>
                <id>12</id>
                <label>Contract 3 for Eric SPRITZ : Car insurance</label>
            </node>
            <node>
                <id>15</id>
                <label>Contract 3 for Thomas BECK : Car insurance</label>
            </node>
            <node>
                <id>8</id>
                <label>Edith PIAF</label>
            </node>
            <node>
                <id>1</id>
                <label>Eric SPRITZ</label>
            </node>
            <node>
                <id>5</id>
                <label>Joao GILBERTO</label>
            </node>
            <node>
                <id>6</id>
                <label>Luciano PAVAROTTI</label>
            </node>
            <node>
                <id>7</id>
                <label>Maria BETHANIA</label>
            </node>
            <node>
                <id>16</id>
                <label>MARTIN HR file</label>
            </node>
            <node>
                <id>17</id>
                <label>SMITH HR file</label>
            </node>
            <node>
                <id>3</id>
                <label>Teresa CRISTINA</label>
            </node>
            <node>
                <id>2</id>
                <label>Thomas BECK</label>
            </node>
            <node>
                <id>4</id>
                <label>Tom JOBIM</label>
            </node>
        </values>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
</fields>
</root>
我得到这个错误


实体:第1行:解析器错误:需要开始标记,“尝试将空标记
替换为

虽然在技术上是正确的,但它可能会使解析器出错

除此之外,它在我看来就像格式良好的XML。

执行以下代码:

<?php

$str =<<<XML_CONTENT
<?xml version='1.0'?>
<root>
  <id></id>
  <title>Maarch Capture Connector</title>
  <width>400</width>
  <height>250</height>
  <center>true</center>
  <fields>
    <node>
        <type>comboBox</type>
        <id>ingoing</id>
        <label>Courrier</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>Y</id>
                <label>Arrivée</label>
            </node>
            <node>
                <id>N</id>
                <label>Départ</label>
            </node>
        </values>
        <default_value>Y</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>priority</id>
        <label>Priorité</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>0</id>
                <label>Priorité trés haute</label>
            </node>
            <node>
                <id>1</id>
                <label>Priorité haute</label>
            </node>
            <node>
                <id>2</id>
                <label>Priorité normale</label>
            </node>
            <node>
                <id>3</id>
                <label>Priorité basse</label>
            </node>
        </values>
        <default_value>2</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>services</id>
        <label>Service</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>9</id>
                <label>Compay SEGUNDO</label>
            </node>
            <node>
                <id>10</id>
                <label>Contract 1 for Eric SPRITZ : Life insurance</label>
            </node>
            <node>
                <id>13</id>
                <label>Contract 1 for Thomas BECK : Life insurance</label>
            </node>
            <node>
                <id>11</id>
                <label>Contract 2 for Eric SPRITZ : Home insurance</label>
            </node>
            <node>
                <id>14</id>
                <label>Contract 2 for Thomas BECK : Home insurance</label>
            </node>
            <node>
                <id>12</id>
                <label>Contract 3 for Eric SPRITZ : Car insurance</label>
            </node>
            <node>
                <id>15</id>
                <label>Contract 3 for Thomas BECK : Car insurance</label>
            </node>
            <node>
                <id>8</id>
                <label>Edith PIAF</label>
            </node>
            <node>
                <id>1</id>
                <label>Eric SPRITZ</label>
            </node>
            <node>
                <id>5</id>
                <label>Joao GILBERTO</label>
            </node>
            <node>
                <id>6</id>
                <label>Luciano PAVAROTTI</label>
            </node>
            <node>
                <id>7</id>
                <label>Maria BETHANIA</label>
            </node>
            <node>
                <id>16</id>
                <label>MARTIN HR file</label>
            </node>
            <node>
                <id>17</id>
                <label>SMITH HR file</label>
            </node>
            <node>
                <id>3</id>
                <label>Teresa CRISTINA</label>
            </node>
            <node>
                <id>2</id>
                <label>Thomas BECK</label>
            </node>
            <node>
                <id>4</id>
                <label>Tom JOBIM</label>
            </node>
        </values>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
</fields>
</root>
XML_CONTENT;

$xmlForm = simplexml_load_string($str);

print_r($xmlForm);

echo "Everything is fine !";

?>

马尔奇捕捉连接器
400
250
真的
组合框
迁入
库里耶

工作正常,因此您的字符串初始化可能会有问题(错误的不可见克拉特…?)


注意:添加XML头标记是最好的选择,不应忘记

我已经解决了我的问题。我的XML字符串很好…问题出在我修改过的其他文件中。很抱歉延迟回复,感谢您的帮助:)

尝试添加
并向我们展示如何初始化字符串。尝试添加
我将其粘贴到xmlvalidation.com中,它现在报告了错误,因此可能有一些额外的字符。我不认为这是自关闭标记的问题。请看错误消息…我忘了提到我正在尝试安装与问题有何关系。。?如何初始化旅游XML字符串。?
<?php

$str =<<<XML_CONTENT
<?xml version='1.0'?>
<root>
  <id></id>
  <title>Maarch Capture Connector</title>
  <width>400</width>
  <height>250</height>
  <center>true</center>
  <fields>
    <node>
        <type>comboBox</type>
        <id>ingoing</id>
        <label>Courrier</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>Y</id>
                <label>Arrivée</label>
            </node>
            <node>
                <id>N</id>
                <label>Départ</label>
            </node>
        </values>
        <default_value>Y</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>priority</id>
        <label>Priorité</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>0</id>
                <label>Priorité trés haute</label>
            </node>
            <node>
                <id>1</id>
                <label>Priorité haute</label>
            </node>
            <node>
                <id>2</id>
                <label>Priorité normale</label>
            </node>
            <node>
                <id>3</id>
                <label>Priorité basse</label>
            </node>
        </values>
        <default_value>2</default_value>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
    <node>
        <type>comboBox</type>
        <id>services</id>
        <label>Service</label>
        <autocomplete>false</autocomplete>
        <values>
            <node>
                <id>9</id>
                <label>Compay SEGUNDO</label>
            </node>
            <node>
                <id>10</id>
                <label>Contract 1 for Eric SPRITZ : Life insurance</label>
            </node>
            <node>
                <id>13</id>
                <label>Contract 1 for Thomas BECK : Life insurance</label>
            </node>
            <node>
                <id>11</id>
                <label>Contract 2 for Eric SPRITZ : Home insurance</label>
            </node>
            <node>
                <id>14</id>
                <label>Contract 2 for Thomas BECK : Home insurance</label>
            </node>
            <node>
                <id>12</id>
                <label>Contract 3 for Eric SPRITZ : Car insurance</label>
            </node>
            <node>
                <id>15</id>
                <label>Contract 3 for Thomas BECK : Car insurance</label>
            </node>
            <node>
                <id>8</id>
                <label>Edith PIAF</label>
            </node>
            <node>
                <id>1</id>
                <label>Eric SPRITZ</label>
            </node>
            <node>
                <id>5</id>
                <label>Joao GILBERTO</label>
            </node>
            <node>
                <id>6</id>
                <label>Luciano PAVAROTTI</label>
            </node>
            <node>
                <id>7</id>
                <label>Maria BETHANIA</label>
            </node>
            <node>
                <id>16</id>
                <label>MARTIN HR file</label>
            </node>
            <node>
                <id>17</id>
                <label>SMITH HR file</label>
            </node>
            <node>
                <id>3</id>
                <label>Teresa CRISTINA</label>
            </node>
            <node>
                <id>2</id>
                <label>Thomas BECK</label>
            </node>
            <node>
                <id>4</id>
                <label>Tom JOBIM</label>
            </node>
        </values>
        <show_id>false</show_id>
        <mandatory>true</mandatory>
    </node>
</fields>
</root>
XML_CONTENT;

$xmlForm = simplexml_load_string($str);

print_r($xmlForm);

echo "Everything is fine !";

?>