ShaXbee Posted January 11, 2007 Share Posted January 11, 2007 While working on project, we needed good and simple solutions for creating XML data. SimpleXML have meny limitations, and doesn't suited our needs, DOM needs lots of code for simpliest things and is uncomfortable.Using magic methods and ArrayAccess interface we created class with SimpleXML-like API, extending it with new functions and DOM methods and fields. EasyXML dosen't use lots of memory because it's created on-fly (only where some node is requested). In theory size of XML data is only limited by PHP and DOM capabilities.Download:http://shaxbee.superhost.pl/code/2007/01/EasyXML.class.ziphttp://shaxbee.superhost.pl/code/2007/01/EasyXML-doc/class_e asy_x_m_l.htmlSome usage examples:[code]$xml = new EasyXML('<root><check>someValue</check></root>'); // creates object in SimpleXML manner// lub$xml = EasyXML::loadXMLFile('file.xml'); // loads a file and returns EasyXML object$xml->root->check = 'someOtherValue'; // sets contents of given tag (creates DOM nodes)$xml->root['attribute'] = 'attributeValue'; // sets attribute valueunset($xml->root['attribute']); // removes attribute$domain = $xml->root->check->appendChild('domain');$otherDomain = $xml->root->check->appendChild('domain', 'value'); // creates another child$domain['name'] = 'aqq.pl';unset($xml->root->check->domain); // deletes every check childs with name 'domain'$xml->root->firstChild; // access for DOM fields ...$xml->root->hasAttribute('test'); // ... and methods$xml->root->check = '<domain>aqq</domain><domain>bqq</domain>'; // you can simple set node content (DOM nodes)$data = serialize($xml); // working (SimpleXML :/) serialization$xml->getArray(); // returns node as array, preserving structure of nodes$xml->xpath('//check'); // xpath is also workingecho $xml; // (string) $xml returns XML data[/code]Feel free to play with that class, i'm waiting for feedback :) Link to comment https://forums.phpfreaks.com/topic/33765-easyxml-simple-as-simplexml-powerful-like-dom/ Share on other sites More sharing options...
Recommended Posts