servo-php / fluidxml

FluidXML, the PHP library for manipulating XML with a concise and fluent API.
BSD 2-Clause "Simplified" License
458 stars 45 forks source link

Better way to append a DOMNode #5

Closed tolgaulas closed 8 years ago

tolgaulas commented 8 years ago

Is there a way (better?) then the below?

$xml = new SimpleXMLElement($inXML); $domxml = dom_import_simplexml($xml); $stripedXML = $domxml->ownerDocument->saveXML($domxml->ownerDocument->documentElement); $outXML = new FluidXml(); $outXML->add('firstlevel',true)->appendXml($inXML);

daniele-orlando commented 8 years ago

Good point. In my workflow it's almost an edge case, but I understand it can be a reasonable situation. Given your suggestion I will commit an ->appendXml() patch to recognize SimpleXMLElement and DOMDocument/DOMNode. Look for the next commit. ;)

daniele-orlando commented 8 years ago

@tolgaulas c21d80a87a185675816a4cb5a3195dee54f468fa improves appendXml() in a way that it recognize DOMNode/DOMNodeList/SimpleXMLElement/FluidXML instances.

In the last release (1.9) appendXml() has been merged with appendChild()/add(). Your code become:

$xml = new SimpleXMLElement($inXML);
$outXML = new FluidXml();
$outXML->add('firstlevel',true)->add($xml);
daniele-orlando commented 8 years ago

Closed by 39053c141f6e44373a33c4ac7967554b79ad5396.