Skip to content

Version 0.6.0

Compare
Choose a tag to compare
@veewee veewee released this 21 May 11:31
v0.6.0
86b7d0f

Total issues resolved: 6

Some highlights:

comparable() configurator

use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Configurator\comparable;
use function VeeWee\Xml\Dom\Locator\document_element;
use function VeeWee\Xml\Dom\Mapper\xml_string;

$raw = <<<EOXML
<foo version="1.9" target="universe">
    <item
        a:sku="xml"
        z:id="3"
        xmlns:a="http://a"
        xmlns:z="http://z"
    >XML</item>
</foo>
EOXML;

$expected = <<<EOXML
<foo xmlns:ns1="http://z" xmlns:ns2="http://a" target="universe" version="1.9">
  <item ns1:id="3" ns2:sku="xml">XML</item>
</foo>
EOXML;

$actualDoc = Document::fromXmlString($raw, comparable());
$actual = $actualDoc->map(static fn (DOMDOcument $doc) => xml_string()($doc->documentElement));

assert($actual === $expected);

xmlns

xmlns_attributes_list($element)
    ->filter(
        static fn (DOMNameSpaceNode $xmlns): bool => (bool) $xmlns->prefix
    )
    ->forEach(
        static function (DOMNameSpaceNode $xmlns) use ($element) {
            remove_namespace($xmlns, $element);
        }
    );

renaming

use function VeeWee\Xml\Dom\Manipulator\Attribute\rename as rename_attribute;
use function VeeWee\Xml\Dom\Manipulator\Element\rename as rename_element;
use function VeeWee\Xml\Dom\Manipulator\Xmlns\rename as rename_xmlns;

rename_attribute($attr, 'foo', $newUri);
rename_element($element, 'foo', $newUri);
rename_xmlns($doc, 'http://namespace', 'prefix');