1
我需要你的帮助与SimpleXML和DOMDocument。我会播下你我当前的代码,然后将解释我的问题:没有XML标记与SimpleXML DOM文档
$xml = new SimpleXMLElement('<milu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://milu.xsd"/>');
$dom = dom_import_simplexml($xml);
$version = $xml->addChild('VERSION', date('m.d.Y'));
while ($row= mysql_fetch_assoc($res)) {
$bev = $xml->addChild('JUICE');
$bev->addAttribute('ID', $row["id"]);
// var_dump($row["name1_german"]);
$bev->addChild('01', $row["Value1"]);
$bev->addChild('02', $row["Value1"]);
$bev->addChild('03', $row["Value1"]);
$bev->addChild('04', $row["Value1"]);
}
$dom_sxe = dom_import_simplexml($xml); // Returns a DomElement object
$dom_output = new DOMDocument('1.0');
$dom_output->formatOutput = true;
$dom_sxe = $dom_output->importNode($dom_sxe, true);
$dom_sxe = $dom_output->appendChild($dom_sxe);
header('Content-Disposition: attachment; filename="milu.xml"');
echo $dom_output->saveXML($dom_output, LIBXML_NOEMPTYTAG);
生成的.xml文件的第一行的输出是这样的:
<?xml version="1.0" encoding="UTF-8"?>
是它与DOM文档可能,这没有出现?
我的第二个问题是,我想围绕这样的循环中的孩子:
<JUICE ID="0000000000">
<CONFIG MODELID="2">
<01>value1</01>
<02>value2</02>
<03>value3</03>
<04>value4</04>
</CONFIG>
</JUICE>
请帮助我。由于
非常感谢! – Florian