Skip to content

Releases: veewee/xml

Version 1.2.0

17 Dec 13:33
v1.2.0
5f4b53c
Compare
Choose a tag to compare

What's Changed

  • Introduce copy_named_xmlns_attributes by @veewee in #24

Full Changelog: v1.1.1...v1.2.0

Version 1.1.1

17 Dec 08:54
v1.1.1
aea7bfd
Compare
Choose a tag to compare

What's Changed

  • Optimize duplicate namespaces on root by @veewee in #23

Full Changelog: v1.1.0...v1.1.1

Version 1.1.0

22 Nov 17:08
v1.1.0
71ab2c5
Compare
Choose a tag to compare

What's Changed

Full Changelog: v1.0.1...v1.1.0

Version 1.0.1

29 Oct 13:09
v1.0.1
185a018
Compare
Choose a tag to compare

Version 1.0.0

24 Sep 05:57
v1.0.0
8cbf2a2
Compare
Choose a tag to compare

Same as previous, but with a BC promise!

Version 0.6.1

24 Sep 05:55
v0.6.1
8cbf2a2
Compare
Choose a tag to compare

Version 0.6.0

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

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');

Version 0.5.0

21 Apr 05:46
v0.5.0
95ddbcd
Compare
Choose a tag to compare

We've got visitors

Total issues resolved: 5

Some highlights:

Node Collections

$total = $xml->locate(elements_with_tagname('products'))
     ->children()
     ->filter(
         static fn(DOMElement $element)
            => $element->getAttribute('active') === 'yes'
     )
     ->query('./price')
     ->reduce(
         static fn(int $total, DOMElement $price)
            => $total + value($price, Type\int()),
         0
     );

Traversable node visitors

$doc = Document::fromXmlFile(
    $file,
    traverse(
        new WazzupVisitor(),
    )
);
class WazzupVisitor extends AbstractVisitor
{
    public function onNodeLeave(DOMNode $node) : Action
    {
        if (!is_attribute($node)) {
            return new Action\Noop();
        }

        attribute($node->nodeName, 'WAZZUP')($node->parentNode);

        return new Action\Noop();
    }
}

Version 0.4.0

09 Mar 06:18
v0.4.0
af5e28b
Compare
Choose a tag to compare

Total issues resolved: 1

$doc = document_encode(['hello' => 'world'], utf8(), pretty_print());

$out = $doc->map(xslt_template($xslt));

Version 0.3.0

03 Mar 14:20
v0.3.0
c603659
Compare
Choose a tag to compare

Encoding

Total issues resolved: 1

$data = xml_decode(
    file_get_contents('file.xml'),
    validator(xsd_validator('some-schema.xsd'))
);

// You can read or change the data
$data['root']['name'] = 'MyName';

// And finally convert it back to XML!
$xml = xml_encode($data, utf8(), pretty_print());