diff --git a/README.md b/README.md index dc526b3..238402d 100644 --- a/README.md +++ b/README.md @@ -48,16 +48,6 @@ $xml = $collection->toSoapXml('Request', 'xmlBody', 'https://yourwebserver/servi **Please note:** the SoapFactory class will ping the ``$fullUrl`` to see if it is valid as it builds the SOAP xml. It will not trigger an api interaction, but you will experience an exception if your url is invalid. -### Xml to collection - -Convert valid xml into an array before wrapping it in a collection: - -```php -$xml = 'fedex1239205590164917312751089'; - -$collection = collect(xml_to_array($xml)); -``` - ### Array to xml Convert an array into xml without using a collection: @@ -80,12 +70,6 @@ $xml = array_to_xml($array); The ``$root`` argument allows you to customize the root xml element. Default is ````. -**Helper** - -``xml_to_array($xml, $outputRoot = false)`` - -The ``$outputRoot`` determines whether or not the php array will have a ``@root`` key. Default is ``false``. - **Collection method** ``->toXml($root)`` diff --git a/src/XmlToArray.php b/src/XmlToArray.php deleted file mode 100644 index 6e7a6e1..0000000 --- a/src/XmlToArray.php +++ /dev/null @@ -1,82 +0,0 @@ -loadXML($xmlstr); - $root = $doc->documentElement; - $output = self::domNodeToArray($root); - $output['@root'] = $root->tagName; - return $output; - } - - protected static function domNodeToArray($node) - { - $output = []; - switch ($node->nodeType) { - case XML_CDATA_SECTION_NODE: - case XML_TEXT_NODE: - $output = trim($node->textContent); - break; - case XML_ELEMENT_NODE: - for ($i = 0, $m = $node->childNodes->length; $i < $m; $i++) { - $child = $node->childNodes->item($i); - $v = self::domNodeToArray($child); - if (isset($child->tagName)) { - $t = $child->tagName; - if (!isset($output[$t])) { - $output[$t] = []; - } - $output[$t][] = $v; - } elseif ($v || $v === '0') { - $output = (string) $v; - } - } - if ($node->attributes->length && !is_array($output)) { // Has attributes but isn't an array - $output = ['@content' => $output]; // Change output into an array. - } - if (is_array($output)) { - if ($node->attributes->length) { - $a = []; - foreach ($node->attributes as $attrName => $attrNode) { - $a[$attrName] = (string) $attrNode->value; - } - $output['@attributes'] = $a; - } - foreach ($output as $t => $v) { - if (is_array($v) && count($v) == 1 && $t != '@attributes') { - $output[$t] = $v[0]; - } - } - } - break; - } - return $output; - } -} diff --git a/src/helpers.php b/src/helpers.php index 33ee223..3600327 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -13,17 +13,3 @@ function array_to_xml($array, $root = '') return \Spatie\ArrayToXml\ArrayToXml::convert($array, $root); } } - -if (!function_exists('xml_to_array')) { - /** - * Convert valid XML to an array. - * - * @param string $xml - * @param bool $outputRoot - * @return array - */ - function xml_to_array($xml, $outputRoot = false) - { - return \Mtownsend\CollectionXml\XmlToArray::convert($xml, $outputRoot); - } -} diff --git a/tests/CollectionXmlTest.php b/tests/CollectionXmlTest.php index 7b45330..f7f4b92 100644 --- a/tests/CollectionXmlTest.php +++ b/tests/CollectionXmlTest.php @@ -64,10 +64,4 @@ public function array_can_convert_to_xml() $xml = $this->removeNewLines(array_to_xml($array)); $this->assertEquals($xml, $this->testXml); } - - /** @test */ - public function xml_can_convert_to_array() - { - $this->assertEquals(xml_to_array($this->testXml), $this->testCollection->toArray()); - } }