-1
我在PHP中有一些字符串,我需要從它們製作XML。PHP從字符串創建XML
工作examle:
$xml = <<<EOT
<?xml version="1.0"?>
<ALL>
<BLOCK id="1" >
<TEXT name="A1" />
<TEXT name="A2" />
</BLOCK>
<BLOCK id="2" >
<TEXT name="B1" />
<TEXT name="B2" />
</BLOCK>
</ALL>
EOT;
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xml);
我actualy已經和它不工作。 :
$string1 = '<TEXT name="A1" />';
$string2 = '<TEXT name="A2" />';
$string3 = '<TEXT name="B1" />';
$string4 = '<TEXT name="B2" />';
$xml = <<<EOT
<?xml version="1.0"?>
<ALL>
<BLOCK id="1" >
$string
$string
</BLOCK>
<BLOCK id="2" >
$string3
$string4
</BLOCK>
</ALL>
EOT;
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xml);
什麼不工作是什麼呢? – felipsmartins