写入xml文件时格式化
|
$doc = new DOMDocument();
$doc->load(\'xml/lead.xml\');
$doc->formatOutput = true;
$tags = $doc->getElementsByTagName(\'RootElement\');
$r = $tags->item(0);
$a = $doc->createElement( \'Lead\' );
$r->appendChild( $a );
$b = $doc->createElement( \'Contact\' );
$b->setAttribute(\'FirstName\', \'\'.$name.\'\');
$b->setAttribute(\'LastName\', \'\'.$last_name.\'\');
$b->setAttribute(\'Email\', \'\'.$email.\'\');
$b->setAttribute(\'StreetAddress\', \'\'.$address.\'\');
$b->setAttribute(\'City\', \'\'.$city.\'\');
$a->appendChild( $b );
$c = $doc->createElement( \'Qualifications\' );
$a->appendChild( $c );
$d = $doc->createElement( \'PropertyInterest\' );
$d->setAttribute(\"BuilderName\",\"Test\");
$a->appendChild( $d );
输出到文件,看起来像
<RootElement>
<Lead><Contact FirstName=\"test \" LastName=\"test\" Email=\"testk@gmail.com\" StreetAddress=\"n/a\" City=\"test\"/><Qualifications/><PropertyInterest BuilderName=\"test\"/></Lead></RootElement>
大量的空白...我将其提交给CRM,并且我假设空白确实在解析方式方面有所不同。
那么,如何使用DOMDocument格式化xml?
没有找到相关结果
已邀请:
1 个回复
攫怂绵十