amba XML document

Package:
amba XML document
Summary:
Extend the DOM XML classes
Groups:
PHP 5, XML
Author:
Alexey V Ryazhskikh
Description:
This package extends the DOM XML classes to provide additional functionality.

The DOM Document extension class can return the document root element, add a new node to the end of the document, select nodes that match a XPath expression, call a function for a list of elements and transform a document using XSL.

The DOM element extension class can get XML for the owner document, get the node XPath, get child nodes, select child nodes that match a XPath expression, get the parent and sibling nodes, get and set attributes by name, copy attributes, add child nodes and character data, import and export nodes to and from another document, set and get the inner XML of a node, call a function for nodes that map a XPath expression, etc..

Standard DOMDocument has rich functionality, but it is not handy enough. XMLDocument is extension of standard PHP DOMDocument and DOMElement.


This project contains two classes for easy create, navigate and process XML documents.

Main features is:

* SelectSingleNode and SelectNodes - node related functions works like same functions in C#.
* Inner XML getting/setting - easy and in one line.
* Chain style to create new node sets.
* Functions for frequently used actions: copy attributes, delete all childs etc.

Usage sample:

$doc = new XMLDocument("<Users/>");
$doc->getRoot()->addNode('User')
->setAttribute('Active', 'true')
->addNodeWithCData('Name', 'John')
->getParent()->getParent()
->addNode('User')
->setInnerXML('<Name><![CDATA[Peter]]></Name>');
echo $doc->saveXML();

Result:

<Users>
<User Active="true">
<Name><![CDATA[John]]></Name>
</User>
<User>
<Name><![CDATA[Peter]]></Name>
</User>
</Users>

See Samples for more details.


Powered by Gewgley