PHP Classes
elePHPant
Icontem

QXML: XML <> Array (preserve attrib.), JSON, etc.

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (34)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2008-05-19 (7 years ago) RSS 2.0 feedStarStarStarStar 74%Total: 1,778 All time: 2,074 This week: 1,089Up
Version License PHP version Categories  
qxml 1.0MIT/X Consortium ...5.0XML, PHP 5
Description Author  

This class can be used to generate XML documents from arrays and also parse XML documents to build arrays.

It can work with an XML's textNodes and attributes, stores them into an array and generates an XML document.

This class can also do the opposite, i.e. take an XML document file or string and parse it, and then build an array.

It is quite simple in handling. Just look at the sample files.

Feature List:
- Array to XML Conversion while preserving attributes
- XML to Array Conversion
- XML to SimpleXMLElement Object
- SimpleXMLElement Object to XML
- XML to JSON
- Array to JSON

Other Scripts
- Schema Transformation for usage with Propel or Doctrine ORM
- Google Routes to GPX
- PHP Classes Reflection to XML

to be rewritten and provided later this year:
- QQuery (originally written as a set of classes for usage within symfony framework )

If you have suggestions for making it better then let me know.

Picture of Tom Schaefer
Name: Tom Schaefer is available for providing paid consulting. Contact Tom Schaefer .
Classes: 39 packages by
Country: Germany Germany
Age: ???
All time rank: 1109 in Germany Germany
Week rank: 148 Down4 in Germany Germany Up
Innovation award
Innovation award
Nominee: 9x

Winner: 1x

Details provided by the author  
Motivation:

I wrote QXml because I didn't found a php class that was able to handle array to xml conversion sufficiently. QXML is able to preserve attributes and does a lot more. 

An array structure is geared to the structure of a simple xml object. 
SimpleXMLElement attributes are printed out (via print_r()-method) like the following: [@attributes]

Analogous to this convention you have to declare a nested array by setting its name to @attributes:
array (
  "@attributes" => array("id" => "myID")
  "@textNode" => "MyTextNode Data"
);
If you declare a nested array with @textNode as key, then a CDDATE escaped text node will be created.
Otherwise new elements will be created.

QSet is my favorite array helper class that allows array handling with ease. I adopted it from CakePHP. I renamed it, reconditioned it a bit and made some useful enhancements.

QSet and QXML are working together. It is a strong team. It allows e.g. following:

ARRAY to XML Conversion
XML to Array Conversion
XML to Object Conversion
Array to Object Conversion
(vice versa)

By including the vendor classes Services_JSON from PEAR and the IBM xml2json class you can do this additionally:
XML to JSON Conversion
Array to JSON Conversion
and so on.

The other classes are for now just example classes.

The QReflection class is an extraction from another project where i use it for documentary demands and purposes.

I hope you enjoy this class as i do.

best regards
Thomas Schäfer
  Files folder image Files  
File Role Description
Accessible without login Plain text file data.php Aux. data file using complex node array
Accessible without login Plain text file dbd2propel.xsl Data Transform DB-Designer 4 to Symfony Schema
Accessible without login Plain text file demo_bookshop.xml Data Demo Bookshop XML
Accessible without login Plain text file gpx.xsd Data XSD file adopted from elsewhere.org
Accessible without login Plain text file green1.xsl Data Sample XML for FusionChart Sample
Plain text file JSON.class.php Class Service Class From PEAR
Accessible without login Plain text file menu.xml Data Data File for sample2
Plain text file Propel2Doctrine.class.php Class DBDesigner -> Propel -> Doctrine Conversion
Plain text file QGoogleMapToGPX Class Convert GoogleMap Coordinates to GPS (adopted from JS at elsewhere.org)
Plain text file QReflection.class.php Class Reflection Class
Plain text file QSet.class.php Class Array Class adopted from CakePHP
Plain text file QTransform.class.php Class XSL Transform class
Plain text file QWhoIsIp.class.php Class Sample Class for showing how to convert arrays
Plain text file QXml.class.php Class QXML Class
Accessible without login Plain text file readme.txt Doc. readme
Accessible without login Plain text file residential.xml Data Sample XML for FusionChart Sample
Accessible without login Plain text file residential.xsl Data Sample XSL for FusionChart Sample
Accessible without login Plain text file sample.php Example Sample File
Accessible without login Plain text file sample2.php Example Sample File
Accessible without login Plain text file sample3.php Example Sample File: XML Output from Node for Flash XML
Accessible without login Plain text file sample3b.php Example Showing how to extend xml for FusionChart (XSL,XML)
Accessible without login Plain text file sample4.php Example Sample: Get IP-Info, convert to XML, convert to object and work on it
Accessible without login Plain text file sample5.php Output IP-Info to XML
Accessible without login Plain text file sample6.php Example convert Array to Xml to JSON
Accessible without login Plain text file sample_atom.php Example Sample Atom Feed
Accessible without login Plain text file sample_bookshop.php Example Transform Bookshop XML to Symfony Schema
Accessible without login Plain text file sample_doctrine.php Example Convert a DB Designer Scheme to Doctrine YML Scheme
Accessible without login Plain text file sample_feeds_oo.php Example Sample OO Feed Classes
Accessible without login Plain text file sample_googlegpx.php Example GPX XML from Google Routes
Accessible without login Plain text file sample_opml.php Example Sample OPML Feed
Accessible without login Plain text file sample_reflect.php Example Reflect a class and transform to xml; could be used for documentation
Accessible without login Plain text file sample_rss.php Example Sample RSS Feed
Accessible without login Plain text file Spyc.class.php Aux. SPYC - A Simple PHP YAML Class
Plain text file XMLJSON.class.php Class Service Class From IBM

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,778All time:2,074
 This week:0This week:1,089Up
User Ratings User Comments (1)  
 All time
Utility:100%StarStarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:66%StarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:74%StarStarStarStar
Rank:98
 
Very good piece of code.
4 years ago (joao melo)
80%StarStarStarStarStar