Download the PHP package ottosmops/xmltoolkit without Composer
On this page you can find all versions of the php package ottosmops/xmltoolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ottosmops/xmltoolkit
More information about ottosmops/xmltoolkit
Files in ottosmops/xmltoolkit
Package xmltoolkit
Short Description Add and remove XML tags and attributes.
License MIT
Informations about the package xmltoolkit
Xmltoolkit is a PHP class that provides various utilities for manipulating XML documents. It allows loading XML from files or strings, performing XPath queries (with namespace support), and modifying XML elements and attributes.
Installation
Use Composer to install the package:
Usage
$elements = $xml->findElementsByAttributeRegex('type', '/^sp./'); $xml->replaceAttributeValueRegex('type', '/^sp./', 'normal'); $elements = $xml->findElementsByTextRegex('/old./'); $xml->replaceElementTextRegex('/old./', 'newtext');
Namespace Support
You can register XML namespaces for XPath queries:
Methods
...existing code...
Load an XML file into the DOM object and ensure it is UTF-8 encoded.
Load an XML string into the DOM object and ensure it is UTF-8 encoded.
Load an XML/HTML Fragment
Save the XML document to a file and ensure it is UTF-8 encoded.
Returns the XML as a string and ensures it is UTF-8 encoded.
Find elements by attribute value.
Replace attribute value for all elements with a given attribute value.
Find elements by text content.
Replace text content for all elements with a given text content.
Rename a tag found by an XPath expression.
Rename an attribute found by an XPath expression.
Add a new attribute to a tag found by an XPath expression.
Remove an attribute from a tag found by an XPath expression.
Does an arbitrary XPath query and returns the found nodes as an array.
Inserts an HTML string after the nodes found by an XPath expression.
Removes an element found by an XPath expression.
Wrap an element found by an XPath expression with a new element.
Remove an element but keep its content (unwrap the element) based on an XPath expression.
Tests
Regex Features
Methods
Find elements by attribute value using regex:
Replace attribute value using regex:
Find elements by text content using regex:
Replace text content using regex:
Usage
Tests
Run the tests with PHPUnit: