开发者

formatting when writing to an xml file

  $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","Tes开发者_JS百科t");

  $a->appendChild( $d ); 

outputs to a file and looks like

<RootElement>






<Lead><Contact FirstName="test " LastName="test" Email="testk@gmail.com" StreetAddress="n/a" City="test"/><Qualifications/><PropertyInterest BuilderName="test"/></Lead></RootElement>

there's tons of whitespace... im submitting this to a CRM and i'm assuming that whitespace does make a difference in how it's parsed.

So, how do I format the xml using the DOMDocument?


if that lib is anything like jdom you should be able to set the format on the outputter. something along theses lines:

out.setFormat(Format.getPrettyFormat());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜