PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 64%Total: 1,849 All time: 2,131 This week: 51Up
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
  Performance   Level  
Name: Tom Schaefer is available for providing paid consulting. Contact Tom Schaefer .
Classes: 39 packages by
Country: Germany Germany
Age: ???
All time rank: 1088 in Germany Germany
Week rank: 195 Down13 in Germany Germany Down
Innovation award
Innovation award
Nominee: 9x

Winner: 1x

Recommendations

What is the best PHP array to xml class?
Generate XML from the multi dimensional

Example

<?php
include("QXml.class.php");

$caption = "Vacation";

$nodes = array(
 
"@attributes" => array(
   
"dateformat" => "yyyy-mm-dd",
   
"dateformat" => "yyyy-mm-dd",
   
"hoverCapBorderColor" => "2222ff",
   
"hoverCapBgColor" => "e1f5ff",
   
"ganttWidthPercent" => 60,
   
"ganttLineAlpha" => 80,
   
"canvasBorderColor" => "024455",
   
"canvasBorderThickness" => 0,
   
"gridBorderColor" => "4567aa",
   
"gridBorderAlpha" => 20,
  ),
 
"categories" => array(
    array(
     
"@attributes" => array(
       
"bgColor" => "4567aa"
     
),
     
"category" => array(
        array(
         
"@attributes" => array(
           
"start" => "2008-01-01",
           
"end" => "2008-12-31",
           
"align" => "center",
           
"fontColor" => "ffffff",
           
"isBold" => 1,
           
"fontSize" => 14,
           
"name" => $caption,
            )
        ),
        array(
         
"@attributes" => array(
           
"start" => "2008-01-01",
           
"end" => "2008-12-31",
           
"align" => "center",
           
"font" => "Verdana",
           
"fontColor" => "ffffff",
           
"isBold" => 1,
           
"fontSize" => 11,
           
"name" => "Monate",
            ),
        ),
        array(
         
"@attributes" => array(
           
"bgColor" => "4567aa",
           
"fontColor" => "ff0000",
            ),
        ),
       
      )
    )
  )
);

$xml = new QXML;
$xml->toXML($nodes);
header("content-type:text/xml");
echo
$xml->asXML();

?>


Details

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 (34)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,849
This week:0
All time:2,131
This week:51Up
User Ratings User Comments (1)
 All time
Utility:87%StarStarStarStarStar
Consistency:79%StarStarStarStar
Documentation:62%StarStarStarStar
Examples:70%StarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:652
 
Very good piece of code.
13 years ago (joao melo)
80%StarStarStarStarStar