PHP Classes

PHP Merge XML: Merge XML sources from strings, files, DOM objects

Recommend this page to a friend!
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (1 month ago) RSS 2.0 feedStarStarStarStar 65%Total: 540 All time: 5,575 This week: 73Up
Version License PHP version Categories
merge-xml 1.0.20BSD License5.3XML, PHP 5
Description 

Author

This class can merge XML sources from strings, files or DOM objects.

It can take a XML document from a string, a file or a DOM object tree and merges with another XML document.

The resulting document can be searched using a XPath query string or returned as a string or a DOM object.

This class provides options to control whether the nodes with the same path or name are replaced or added sequentially.

Innovation Award
PHP Programming Innovation award nominee
May 2014
Number 5


Prize: One downloadable e-book of choice by O'Reilly
PHP has extensive support to parse and generate XML documents.

This class extends that support by making it easier to merge XML nodes from multiple documents.

Manuel Lemos
Picture of Vallo Reima
  Performance   Level  
Name: Vallo Reima <contact>
Classes: 6 packages by
Country: Estonia Estonia
Innovation award
Innovation award
Nominee: 3x

Details

PHP MergeXML class ================== The class allows to merge the XML sources (files, strings, objects) into single DOM XML object. The merging is performed recursively on the node level adding new elements and replacing existing ones. The nodes with the same path/name are replaced/added sequentially and the modification can be controlled by the options. MergeXML could be useful in cases where it is necessary to gather XML data from multiple sources. For example, to join the configuration files of different subsystems depending on the system operation. The usage --------- **$oMX = new MergeXML([$opts]);** $opts - the options array: - join - common root name if any source has different root name (default is *root*, specifying *false* denies different names) - updn - traverse the nodes by name sequence (*true*, default) or overall sequence (*false*) - stay - the destination node *stay* attribute value to deny overwriting of specific node (default is *all*, can be array of values or empty) - keep - the source node *keep* attribute value to deny overwriting of specific node (default is *all*, can be array of values or empty) **$oMX->AddFile($file)**; > $file - XML file's pathed name **$oMX->AddSource($source)**; > $source - XML string or DOM object The methods merge a sequent source and return the final object or *false* if failed (see *error* property below). You can search in the result object: **$oMX->Query($expr)**; > $expr - XPath query expression You can get the XML result tree: **$oMX->Get([0|1|2])**; - 0 - object (default) - 1 - text - 2 - html The result object can be accessed also via *$oMX->dom* property. The properties available: - **dom** - result XML DOM object - **dxp** - result XPath object - **nsp** - namespaces array (prefix => URI) - **count** - number of sources merged - **error** - error information - error->code ('' is ok) - error->text The sources must have the same default namespace (if have at all). Prefix '_' is reserved to handle default namespace. The package ----------- The following files are included: 1. *mergexml.php* - the MergeXML class; requires PHP 5.3+; 2. *example.html* - client-side to select the xml files and display result; 3. *example.php* - server-side to receive & pass the xml data and return result; 4. *test1.xml, test2.xml* - test data for the example; 5. *packxml.php* - utility class to minify XML source. The MergeXML is realized also in JavaScript (see [github.com]). ChangeLog --------- May 2014 - *mergexml.php* - *stay* parameter is added for *AddFile* and *AddSource* methods - *NameSpaces* method is added to register/xpath 1st (single) source September 2015 - *mergexml.php* - *fmt* and *enc* parameters are added - *packxml.php* utility is added to compress the XML string December 2015 - *mergexml.php* - *keep* parameter is added for *__construct*, *AddFile* and *AddSource* methods April 2017 - *mergexml.php* - [PackApp] obfuscation compatibility May 2018 - *mergexml.php* - case-insensitive encoding checking July 2019 - *example.html* - select multiple files (html5) [github.com]: http://www.github.com/hareko/js-merge-xml [PackApp]: http://vregistry.com/packapp

  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.html Data Sample output
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file mergexml.php Class Class source
Plain text file packxml.php Class Create
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test1.xml Data Auxiliary data
Accessible without login Plain text file test2.xml Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:540
This week:0
All time:5,575
This week:73Up
User Ratings User Comments (1)
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:626
 
This is a good class ;-)
9 years ago (José Filipe Lopes Santos)
80%StarStarStarStarStar