Download the PHP package vierbergenlars/xml without Composer

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

XML

Build Status Scrutinizer Quality Score Latest Stable Version

A sane wrapper around SimpleXML

Installation

composer require vierbergenlars/xml:@stable

Protip: you should browse the vierbergenlars/xml page to choose a stable version to use, avoid the @stable meta constraint.

Usage

Only the XmlElement class should be instanciated in your code.

The examples are based around following xml structure:

This example is a copy of example.php, which is available in the repository for experimentation.

XmlElement::attr($name) gets the value of the XML attribute $name on the current element.

XmlElement::children() gets the immediate children of the current element. The result implements XmlCollectionInterface. It is an Iterator, implements ArrayAccess and Countable.

For easier chaining in PHP 5.3, a $XmlCollectionInterface->get($idx) function is provided, which has the same effect as $XmlCollectionInterface[$idx].

A ->find($attrs = array()) function is provided that returns a new XmlCollectionInterface, which only contains elements with the attributes passed to the function.

The first element is selected, and the text between its tags is returned (with ->text()).`

Here, the children of $file are filtered to contain only elements with tagname <link>.

All attributes from the <link> element are selected. $link->attributes() returns an implementation of XmlAttributesInterface. The object acts as a read-only array with attribute names as keys and attribute values as value. Additionally, it has a ->get($idx) function for easier chaining.

This is an example of using XmlCollectionInterface::find() to only select the one <link> element with the desired attributes. An equivalent using XmlElementInterface::child() is commented-out below.

Reference

XmlElementInterface

Return Function signature Documentation
string getName() Get the element tag name
string text() Get the text contained in the element
XmlElementInterface setText(string $text) Set the text contained in the element to $text. Returns itself.
string attr(string $name) Get the value of the attribute $name on the element (equivalent to ->attributes()->get($name))
XmlAttributesInterface attributes() Gets all attributes on the element
XmlElementInterface child(string $name = null, array $filter = array(), int $n = 0) Gets the $nth child with the specified name (equivalent to ->children($name)->find($filter)->pos($n))
XmlElementInterface addChild(string $name) Adds a child with tagname $name to the current element. The returned element can be modified.
XmlElementInterface addChild(string $name, string $text) Adds a child with tagname $name and text content $text (->addChild($name)->setText($text))
XmlElementInterface addChild(string $name, XmlElementInterface $element) Adds a child with tagname $name and sets its content and attributes to the same as $element
XmlElementInterface addChild(XmlElementInterface $element) Adds a child to the current element, with tagname, content and attributes the same as $element
XmlCollectionInterface children(string $name = null) Get all children of the element (or only those with the specified name if $name !== null)
XmlCollectionInterface find(array $attributes = array()) Get the children of the element whose attributes match those in $attributes.

XmlCollectionInterface

Implements interfaces Iterator, ArrayAccess, Countable

Return Function signature Documentation
XmlElementInterface get(int $pos) Get the element at the given position
XmlElementInterface add($name, $value = null) Calls XmlElementInterface::addChild() on the parent element
XmlCollectionInterface find(array $attributes = array()) Filters members of the collection on their attributes
int count() Countable::count() Count the elements in the collection
boolean offsetExists(int $offset) ArrayAccess::offsetExists Whether a offset exists (see get())
XmlElementInterface offsetGet(int $offset) ArrayAccess::offsetGet() Offset to retrieve
- offsetSet() Throws LogicException. The collection cannot be modified in this way
- offsetUnset(int $offset) ArrayAcess:offsetUnset() Removes element at $offset from collection
XmlElementInterface current() Iterator::current() Return the current element
int key() Iterator::key() Return key of the current element
void next() Iterator::next() Move forward to next element
void rewind() Iterator::rewind() Rewind the iterator to the first element
boolean valid() Iterator::valid() Checks if current position is valid
  1. This object implements ArrayAccess:

    • $xmlCollectionInterface[$offset] calls $xmlCollectionInterface->offsetGet($offset)
    • isset($xmlCollectionInterface[$offset]) calls $xmlCollectionInterface->offsetExists($offset)
    • $xmlCollectionInterface[$offset] = $mixed calls $xmlCollectionInterface->offsetSet($offset, $mixed) and throws an exception.
    • unset($xmlCollectionInterface[$offset]) calls $xmlCollectionInterface->offsetUnset($offset)
  2. This object implements Countable:

    • count($xmlCollectionInterface) calls $xmlCollectionInterface->count()
  3. This object implements Iterator
    • foreach($xmlCollectionInterface as $key => $value){} calls $xmlCollectionInterface->rewind() once, $xmlCollectionInterface->valid() before each iteration, and if it returns true sets $key = $xmlCollectionInterface->key(); $value = $xmlCollectionInterface->current(). Finally calls $xmlCollectionInterface->next().

XmlAttributesInterface

Implements interfaces Iterator, ArrayAccess, Countable

Return Function signature Documentation
string or null get(string $name) Get the value of the attribute $name
XmlAttributesInterface set(string $name, strinv $value) Sets attribute $name to value $value. Returns itself
int count() Countable::count() Count the elements in the collection
boolean offsetExists(string $attr) ArrayAccess::offsetExists() Whether an attribute exists
string or null offsetGet(string $attr) ArrayAccess::offsetGet() Attribute to retrieve (see get())
- offsetSet(string $attr, string $val ) ArrayAccess:offsetSet() Sets attribute to a value (see set())
- offsetUnset(string $attr) ArrayAccess::offsetUnset() Removes attribute from element
string current() Iterator::current() Return the current element
string key() Iterator::key() Return key of the current element
void next() Iterator::next() Move forward to next element
void rewind() Iterator::rewind() Rewind the iterator to the first element
boolean valid() Iterator::valid() Checks if current position is valid
  1. This object implements ArrayAccess:

    • $xmlAttributesInterface[$offset] calls $xmlAttributesInterface->offsetGet($offset)
    • isset($xmlAttributesInterface[$offset]) calls $xmlAttributesInterface->offsetExists($offset)
    • $xmlAttributesInterface[$offset] = $mixed calls $xmlAttributesInterface->offsetSet($offset, $mixed)
    • unset($xmlAttributesInterface[$offset]) calls $xmlAttributesInterface->offsetUnset($offset)
  2. This object implements Countable:

    • count($xmlAttributesInterface) calls $xmlAttributesInterface->count()
  3. This object implements Iterator
    • foreach($xmlAttributesInterface as $key => $value){} calls $xmlAttributesInterface->rewind() once, $xmlAttributesInterface->valid() before each iteration, and if it returns true sets $key = $xmlAttributesInterface->key(); $value = $xmlAttributesInterface->current(). Finally calls $xmlAttributesInterface->next().

License

MIT


All versions of xml 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 vierbergenlars/xml contains the following files

Loading the files please wait ....