Download the PHP package nigelrel3/xml-reader-reg without Composer

On this page you can find all versions of the php package nigelrel3/xml-reader-reg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package xml-reader-reg

XMLReaderReg

An extension of PHP's XMLReader to include a simplified interface.

Quick Start

XMLReaderReg can be installed using

Rather than having to use boiler plate code to fetch particular elements, XMLReaderReg allows you to register an interest in certain elements along with a callback. This effectively changes it from a pull parser to a push parser.

The main addition is the process() method, rather than looping through the document structure, process() is passed an array of regex and associated callback elements. When a particular XML element matches the pattern you are interested in the callback will be passed the data from that element.

How the document hierarchy is encoded

As the document is loaded, the code builds a simple document hierarchy based on the nesting of the elements. So...

will produce the following tree...

To allow for multiple elements, this is slightly modified to keep track of the number of elements...

will produce the following tree...

Note that the first instance doesn't get a suffix (as it doesn't yet know there is any more elements of this name) and they start at 1 when added.

The array elements are remembered at any particular level of nesting, so

will produce the following tree...

Regex matching

The matching process is as simple as working out where the data you want lies in the document. You can be as explicit or as vague as you wish using regex's ability to match the content of the above hierarchy.

From the quick start sample code...

directly matches an element in the hierarchy, whereas

will find any <person> element and allow an optional suffix for use when multiple elements are present.

Also something useful in regex's is capture groups, notice that this last regex is actually (.*/person(?:\[\d*\])?) in the code. The capture groups will be passed to the callback.

The callback function

The basic callback function definition is

data

The data content of the matching element. This can be type hinted to a string, SimpleXMLElement or DOMElement.

In this callback,

as there is no typehint for the callback value, it will be passed the results of readInnerXml() which is a string containing just the contents of the XML element.

There are a couple of alternatives which are more specific...

the last 2 allow you to fetch the content in a more accessible format if you need to do any further processing.

For DOMElement the equivalent of $reader->importNode($reader->expand(), true) is passed.

For SimpleXMLElement the equivalent of simplexml_import_dom(importNode($reader->expand(), true)) is passed.

path

The capture group(s) from the regex.

If you don't use capture groups, you can omit the $path parameter. If you do use capture groups, then it will pass an array which is the return value of $matches from preg_match() which is used internally to check the path against the regex patterns.

Options

DOM Document owner

When using DOMDocument, the owner of a created node can be important. If you want to control this, then create your own instance of DOMDocument and pass that to this call. Any subsequently generated nodes passed to callbacks will be owned by this document.

If this is not called, all nodes will be owned by an internally created document.

Namespace usage - Matching

Flag to indicate if the path is built with namespaces or not. By default, this flag is set to true and will use namespaces where defined in the document.

With

set to true, it will generate a path hierarchy of

set to false, it will generate a path hierarchy of

Namespace usage - Output

If you don't need/want the namespaces in the output, calling this with false will remove all namespaces from the output. This includes the definition and any namespaces prefixes from the nodes.

Due to the processing this will incur an overhead.

Configuring array notation

By default array notation is turned off, this will present duplicated elements as

This removes the need to include a regex to match the optional array index in (for example) (.*/person(?:\[\d*\])?) and just use (.*/person) to retrieve every <person> element.

In some cases you may not need to know which instance of an element is being processed, this allows you to extract a specific instance or simply to know from the path what instance is being processed.

Calling this with false will stop the generation of array indicies when matching is done. So from the above example the path will look like the following...

Stop the processing

During a callback, you may decide that you do not need to process any more of the content, this method will flag the process() method to stop at the next iteration.

This can be done something like...

Examples

examples/XMLReaderBasic.php has a brief set of examples on how to use XMLReaderReg

Tests

tests/XMLReaderRegTest.php is a PHPUnit test set for XMLReaderReg.

Please note that testFetchLargeFullRead reads a 25MB XML file so will take some time to complete.

License

Please see the LICENSE file.


All versions of xml-reader-reg with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nigelrel3/xml-reader-reg contains the following files

Loading the files please wait ....