Releases: veewee/xml
Releases · veewee/xml
Version 1.2.0
What's Changed
Full Changelog: v1.1.1...v1.2.0
Version 1.1.1
What's Changed
Full Changelog: v1.1.0...v1.1.1
Version 1.1.0
Version 1.0.1
Total issues resolved: 1
Version 1.0.0
Version 0.6.1
Version 0.6.0
Total issues resolved: 6
- 14: Upgrade to GitHub-native Dependabot thanks to @dependabot-preview[bot]
- 15: Improved xmlns support
- 16: Add canonicalize configurator
- 17: Optimize namespaces manipulator and comparable() configurator
- 18: Add functions for renaming nodes
- 19: Improve consistency
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
Total issues resolved: 5
- 8: Add replace by external nodes dom manipulator
- 9: Add DOM validator interface
- 10: DOM Node collections
- 11: Remove deps
- 13: DOM traverser
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
Total issues resolved: 1
$doc = document_encode(['hello' => 'world'], utf8(), pretty_print());
$out = $doc->map(xslt_template($xslt));
Version 0.3.0
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());