写入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?     
已邀请:
如果该lib类似于jdom,则应该能够在输出程序上设置格式。这些观点:
out.setFormat(Format.getPrettyFormat());
    

要回复问题请先登录注册