Created
February 26, 2016 14:17
-
-
Save ericmulder/1e3bf4592d7c0463127d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BetterXMLElement extends SimpleXMLElement { | |
//appends this xml to a parent | |
public function appendToSimpleXML(SimpleXMLElement $parent) { | |
$toDom = dom_import_simplexml($parent); | |
$fromDom = dom_import_simplexml($this); | |
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); | |
} | |
//appends $child SimpleXMLElement to this object | |
public function appendChild(SimpleXMLElement $child) { | |
$toDom = dom_import_simplexml($this); | |
$fromDom = dom_import_simplexml($child); | |
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); | |
} | |
} | |
//use like | |
$xml = new \BetterXMLElement('<financials/>'); | |
$xml->addChild('matchtype', 'customersupplier'); | |
$xml->addChild('duedays', 14); | |
$xml->addChild('payavailable', 'false'); | |
$xml->addChild('meansofpayment', 'none'); | |
$xml->addChild('collectionschema', 'core'); | |
$customer = new \BetterXMLElement('<customer/>'); | |
$customer->appendChild($xml); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment