Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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/13.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生成特定格式的xml_Php_Xml - Fatal编程技术网

使用php生成特定格式的xml

使用php生成特定格式的xml,php,xml,Php,Xml,嗨,我想创建一个php代码,生成下面给出的特定格式的xml。请帮我解决这个问题 <?xml version="1.0" encoding="utf-8"?> <order> <requisition> <dateofservice>2012-12-13</dateofservice> <labid>str1234</labid> <reqnotes_c

嗨,我想创建一个php代码,生成下面给出的特定格式的xml。请帮我解决这个问题

<?xml version="1.0" encoding="utf-8"?>
<order>
    <requisition>
        <dateofservice>2012-12-13</dateofservice>
        <labid>str1234</labid>
        <reqnotes_c>str1234</reqnotes_c>
        <rptemail_c>str1234</rptemail_c>
        <rptmethod_c>str1234</rptmethod_c>
        <specimen_type_c>str1234</specimen_type_c>
        <collectiontype_c>str1234</collectiontype_c>
    </requisition>
    <patient>
        <firstname>str1234</firstname>
        <lastname>str1234</lastname>
        <dob>2012-12-13</dob>
        <breed_c>str1234</breed_c>
        <species>str1234</species>
        <sex>s</sex>
        <sterilization_c>str1234</sterilization_c>
    </patient>
</order>

堆栈溢出不是代码编写服务。如果您有特定的问题,人们会帮助您,但我们不是来为您工作的。@蓝狐现在您能纠正我吗输入在哪里?输入文件是csv文件
while (($row = fgetcsv($inputFile)) !== FALSE){
    $container = $doc->createElement('row');
    foreach($headers as $i => $header) {
        if(!empty($row[$i])) {
            $child = $doc->createElement($header);
            $child = $container->appendChild($child);
            $value = $doc->createTextNode($row[$i]);
            $value = $child->appendChild($value);
        }
    }
    $root->appendChild($container);
}
$strxml = $doc->saveXML();