php创建xml

getVoArrayToday($beginToday, $endToday);

        // 创建DOMDocument对象
        $doc = new DOMDocument('1.0', 'UTF-8');

        // 创建根元素
        $root = $doc->createElement('SIGNATURE');
        $root->setAttribute("xmlns", "qxjg.hebfda.gov.cn");
        $doc->appendChild($root);

        $object = $doc->createElement('OBJECT');
        $root->appendChild($object);

        $package = $doc->createElement('PACKAGE');
        $object->appendChild($package);

        $envelopinfo = $doc->createElement('ENVELOPINFO');
        $package->appendChild($envelopinfo);


        $version = $doc->createElement("VERSION", "1111111111111111");
        $message_id = $doc->createElement("MESSAGE_ID", "1111111111111111");
        $file_name = $doc->createElement("FILE_NAME", "1111111111111111");
        $message_typ = $doc->createElement("MESSAGE_TYP", "1111111111111111");
        $sender_id = $doc->createElement("SENDER_ID", "1111111111111111");
        $send_time = $doc->createElement("SEND_TIME", "1111111111111111");
        $receiver_id = $doc->createElement("RECEIVER_ID", "1111111111111111");
        $softtype = $doc->createElement("SOFTTYPE", "1111111111111111");
        $sendername = $doc->createElement("SENDERNAME", "1111111111111111");
        $envelopinfo->appendChild($version);
        $envelopinfo->appendChild($message_id);
        $envelopinfo->appendChild($file_name);
        $envelopinfo->appendChild($message_typ);
        $envelopinfo->appendChild($sender_id);
        $envelopinfo->appendChild($send_time);
        $envelopinfo->appendChild($receiver_id);
        $envelopinfo->appendChild($softtype);
        $envelopinfo->appendChild($sendername);

        $dataInfo = $doc->createElement('DATAINFO');
        $package->appendChild($dataInfo);


        $dataEle = ['CPID', 'DI', 'PI', 'YPPH', 'XLH', 'SC_DATE', 'SX_DATE', 'PUDI', 'PACKAGE_LE', 'SNUM', 'SUDI', 'NUM', 'UNIT', 'JZ_DATE', 'FPH', 'MER_CODE', 'MER_NAME', 'MERA_CODE', 'BILL_TYPE'];

        $purList = array(
            array('name' => 'John', 'age' => 30, 'gender' => 'male'),
            array('name' => 'Jane', 'age' => 25, 'gender' => 'female'),
            array('name' => 'Bob', 'age' => 45, 'gender' => 'male')
        );

        foreach ($purList as $k => $v) {
            $rowInfo = $doc->createElement('ROWINFO');
            $dataInfo->appendChild($rowInfo);
            $data = ["aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaaaa"];

            for ($i=0;$icreateElement($dataEle[$i], $data[$i]);
                $rowInfo->appendChild($dom);
            }


        }
        echo $doc->saveXML();
        // 输出XML文件
        // $doc->save('books.xml');


        break;


    default:
        echo "参数不匹配";
        return;
}

你可能感兴趣的:(数据库)