Download the PHP package ikr/xml-fu without Composer

On this page you can find all versions of the php package ikr/xml-fu. 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-fu

Build Status

About

Handy utility functions to query XML. Was initially written to simplify dealing with raw SOAP responses, but can also be useful in general, enabling a more functinal style of extracting data from XML.

Installation

Requires PHP 5.3+ and Composer.

composer require ikr/xml-fu:~1.1

API

Core

XmlFu\value($xml, $xpath, $default)

Searches the $xml string for the first node matching the given $xpath, and returns its string value. If the node wasn't found, the $default value is returned.

XmlFu\firstNode($xml, $xpath)

Returns a SimpleXMLElement instance for the first node matching the given $xpath in the given $xml string.

XmlFu\chunks($xml, $xpath)

Finds all the nodes in the passed $xml string matching the given $xpath, and returns an array of their asXML() serializations -- strings.

XmlFu\attrValues($xml, $elementXpath, $attrName)

Finds all the elements in the passed $xml string matching the given $elementXpath, and returns an array of their $attrName attribute values -- one string value per element.

Core without parsing

There are *Impl versions of the core functions, accepting $rootElement-s -- SimpleXMLElement instances instead of the $xml strings.

XmlFu\valueImpl($rootElement, $xpath, $default)
XmlFu\firstNodeImpl($rootElement, $xpath)
XmlFu\chunksImpl($rootElement, $xpath)
XmlFu\attrValuesImpl($rootElement, $elementXpath, $attrName)

That way you can avoid unnecessary multiple parsing runs when querying for multiple values.

Dealing with the default namespace

SimpleXMLElement::xpath() have some quirks dealing with the default XML namespace declaration: the xmlns="..." attribute. As soon as it's present, all the nodes contained by the element with xmlns declared, and the declaring element itself must be prefixed with a namespace in XPath queries. XmlFu conveniently aliases the default namespace with underscore -- _

Thus,

$xml = <<<XML
    <OTA_PingRS xmlns="http://www.opentravel.org/OTA/2003/05">
        <Success />
        <EchoData>Hey!</EchoData>
    </OTA_PingRS>    
XML;

echo XmlFu\value($xml, '//_:EchoData', null); // 'Hey!'

Extras

XmlFu\removeXmlProcessingInstruction($xml)

Removes the <?xml ... declaration from the passed $xml string. The removal is done in a safe way: no reg-exps, honest parsing.

XmlFu\rootTagName($xml)

The name of the topmost XML element in the passed $xml string.

Development status

Used in production.


All versions of xml-fu with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
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 ikr/xml-fu contains the following files

Loading the files please wait ....