读书人

PHP写XML资料

发布时间: 2012-08-26 16:48:06 作者: rapoo

PHP写XML文件

<?php    $domain = "DOMAIN";    $username = "USERNAME";     $owner = "OWNER" ;    $template = "TEMPLATE" ;    $description = "DESCRIPTION" ;    $topics = "TOPICS" ;    $subject  = "SUBJECT" ;    $xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n        <batchcommands>\n    \n</batchcommands>";    $xml = new SimpleXMLElement($xmlstr);    $create = $xml->addchild('create');    $mailing_list = $create->addchild('mailing_list');    $mailing_list->addAttribute('domain', ($domain));    $mailing_list->addAttribute('username', ($username));    $mailing_list->addChild('owner', $owner);    $mailing_list->addChild('template', $template);    $mailing_list->addChild('description', $description);    $mailing_list->addChild('topics', $topics);    $mailing_list->addChild('subject', $subject);    $xml->asXML("C:/create.xml");?>


生成文件内容:
<?xml version="1.0" encoding="UTF-8"?><batchcommands><create><mailing_list domain="DOMAIN" username="USERNAME"><owner>OWNER</owner><template>TEMPLATE</template><description>DESCRIPTION</description><topics>TOPICS</topics><subject>SUBJECT</subject></mailing_list></create></batchcommands>



读书人网 >XML SOAP

热点推荐