Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 没有包含SimpleXML和DOM文档的xml标记_Php_Xml_Loops_Dom_Simplexml - Fatal编程技术网

Php 没有包含SimpleXML和DOM文档的xml标记

Php 没有包含SimpleXML和DOM文档的xml标记,php,xml,loops,dom,simplexml,Php,Xml,Loops,Dom,Simplexml,我需要您对SimpleXML和DOMDocument的帮助。我将向您介绍我当前的代码,然后解释我的问题: $xml = new SimpleXMLElement('<milu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://milu.xsd"/>'); $dom = dom_import_simplexml($xml); $version = $xm

我需要您对SimpleXML和DOMDocument的帮助。我将向您介绍我当前的代码,然后解释我的问题:

$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=新的SimpleXMLElement(“”);
$dom=dom\u import\u simplexml($xml);
$version=$xml->addChild('version',date('m.d.Y');
while($row=mysql\u fetch\u assoc($res)){
$bev=$xml->addChild('JUICE');
$bev->addAttribute('ID',$row[“ID”]);
//var_dump($row[“name1_德语]);
$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);//返回一个DomeElement对象
$dom_output=新的DOMDocument('1.0');
$dom_output->formatOutput=true;
$dom_sxe=$dom_output->importNode($dom_sxe,true);
$dom_sxe=$dom_output->appendChild($dom_sxe);
标题('Content-Disposition:attachment;filename=“milu.xml”');
echo$dom\u output->saveXML($dom\u output,LIBXML\u NOEMPTYTAG);
生成的.xml文件的第一行的输出如下:

<?xml version="1.0" encoding="UTF-8"?>

DOMDocument是否有可能不显示这一点

我的第二个问题是,我想要一个这样的孩子:

<JUICE ID="0000000000">
  <CONFIG MODELID="2">
    <01>value1</01>
    <02>value2</02>
    <03>value3</03>
    <04>value4</04>
  </CONFIG>
</JUICE>

价值1
价值2
价值3
价值4

请帮帮我。感谢

要删除XML声明标记,请使用仅输出根及其子级的属性:

echo $dom_output->saveXML($dom_output->documentElement, LIBXML_NOEMPTYTAG);
if ($res = $dbconn->query($query)) {
    while ($row = $res->fetch_assoc()) {

        $bev = $xml->addChild('JUICE');
        $bev->addAttribute('ID', $row["id"]);

        $config = $bev->addChild('CONFIG');
        $config->addAttribute('MODELID', '2');

        $config->addChild('01', $row["Value1"]);
        $config->addChild('02', $row["Value2"]);
        $config->addChild('03', $row["Value3"]);
        $config->addChild('04', $row["Value4"]);  
    }
}
要添加配置子节点,只需在
$bev
下添加一个子节点,并将每个编号的节点指定为其子节点:

echo $dom_output->saveXML($dom_output->documentElement, LIBXML_NOEMPTYTAG);
if ($res = $dbconn->query($query)) {
    while ($row = $res->fetch_assoc()) {

        $bev = $xml->addChild('JUICE');
        $bev->addAttribute('ID', $row["id"]);

        $config = $bev->addChild('CONFIG');
        $config->addAttribute('MODELID', '2');

        $config->addChild('01', $row["Value1"]);
        $config->addChild('02', $row["Value2"]);
        $config->addChild('03', $row["Value3"]);
        $config->addChild('04', $row["Value4"]);  
    }
}
输出

<milu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://milu.xsd">
  <VERSION>12.04.2016</VERSION>
  <JUICE ID="0000000000">
    <CONFIG MODELID="2">
      <01>value1</01>
      <02>value2</02>
      <03>value3</03>
      <04>value4</04>
    </CONFIG>
  </JUICE>
</milu>

12.04.2016
价值1
价值2
价值3
价值4

最后,请注意,PHP 5中已弃用了
mysql.*
函数,而PHP 7中已完全删除了这些函数。考虑使用不同的PHP MySQL API,如MyQuLi或PDO。上面显示了mysqli中的一个fetch。

要删除XML声明标记,请使用仅输出根及其子级的属性:

echo $dom_output->saveXML($dom_output->documentElement, LIBXML_NOEMPTYTAG);
if ($res = $dbconn->query($query)) {
    while ($row = $res->fetch_assoc()) {

        $bev = $xml->addChild('JUICE');
        $bev->addAttribute('ID', $row["id"]);

        $config = $bev->addChild('CONFIG');
        $config->addAttribute('MODELID', '2');

        $config->addChild('01', $row["Value1"]);
        $config->addChild('02', $row["Value2"]);
        $config->addChild('03', $row["Value3"]);
        $config->addChild('04', $row["Value4"]);  
    }
}
要添加配置子节点,只需在
$bev
下添加一个子节点,并将每个编号的节点指定为其子节点:

echo $dom_output->saveXML($dom_output->documentElement, LIBXML_NOEMPTYTAG);
if ($res = $dbconn->query($query)) {
    while ($row = $res->fetch_assoc()) {

        $bev = $xml->addChild('JUICE');
        $bev->addAttribute('ID', $row["id"]);

        $config = $bev->addChild('CONFIG');
        $config->addAttribute('MODELID', '2');

        $config->addChild('01', $row["Value1"]);
        $config->addChild('02', $row["Value2"]);
        $config->addChild('03', $row["Value3"]);
        $config->addChild('04', $row["Value4"]);  
    }
}
输出

<milu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://milu.xsd">
  <VERSION>12.04.2016</VERSION>
  <JUICE ID="0000000000">
    <CONFIG MODELID="2">
      <01>value1</01>
      <02>value2</02>
      <03>value3</03>
      <04>value4</04>
    </CONFIG>
  </JUICE>
</milu>

12.04.2016
价值1
价值2
价值3
价值4

最后,请注意,PHP 5中已弃用了
mysql.*
函数,而PHP 7中已完全删除了这些函数。考虑使用不同的PHP MySQL API,如MyQuLi或PDO。上面显示了mysqli中的获取。

非常感谢!非常感谢你!