2017 © Pedro Peláez
 

library sxml

Simplest, basic XML document creation

image

sanusart/sxml

Simplest, basic XML document creation

  • Sunday, October 19, 2014
  • by sanusart
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

sXml - Simplest, basic XML document creation


This class will assist in very basic XML document creation., (*1)

Autoload (with composer)

Add "sanusart/sxml": "dev-master" to require array in composer.json, (*2)

Use as:, (*3)

<?php
require 'vendor/autoload.php';          // add autoloader
$xml = new \sanusart\sxml\sxml(true);   // create new instance

Regular php (without composer)

<?php
include_once '../src/Sxml.php';
$xml = new \sanusart\sxml\sxml(true);

Example

if you have PHP > 5.4.0 and php-cli - you can run php -s localhost:8080 inside example directory., (*4)

Basic usage

doctype();
$xml->open('users', array('requered' => 'true', 'type' => 'meta'));

$xml->open('user');
$xml->node('name', 'Sasha');
$xml->node('last_name', 'Khamkov');
$xml->node('alias', 'sanusart');
$xml->node('twitter', '@sanusart');
$xml->node('website', 'http://www.sanusart.com');
$xml->close('user');

$xml->open('no_closing_tag');
$xml->node('node', null, array('requered' => 'true', 'type' => 'data'));
$xml->node('node', null, array('requered' => 'false', 'type' => 'data'));
$xml->node('node', null);
$xml->close('no_closing_tag');

$xml->close('users');
```
will result in:

```

<users type="meta">
<user>
    <name><![CDATA[Sasha]]></name>
    <last_name><![CDATA[Khamkov]]></last_name>
    <alias><![CDATA[sanusart]]></alias>
    <twitter><![CDATA[@sanusart]]></twitter>
    <website><![CDATA[http://www.sanusart.com]]></website>
</user>
</users>

Methods

Constructor()

If $safe is set to true - values of XML nodes will be enclosed inside CDATA, (*5)

Constructor __construct
sXml __construct ([bool $safe = false])

doctype()

access: public, (*6)

Ommiting method attributes for $version and/or $encoding will use default values., (*7)

void doctype ([string $version = '1.0'], [string $encoding = 'utf=8'])
string $version (optional)
string $encoding (optional)

open()

access: public, (*8)

void open ([string $tag], [array $attr = array()])
string $tag
array $attr (optional)

close()

access: public, (*9)

void close ([string $tag])
string $tag

node()

access: public, (*10)

If $value is set - regular node with closing tag will be created e.g. <node></node>. To create a self closed tag <node /> set $value to null., (*11)

void node ([string $tag], [mixed $value], [array $attr = array()])
string $tag
mixed $value | null
array $attr (optional)

The Versions

19/10 2014

dev-master

9999999-dev

Simplest, basic XML document creation

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Sasha Khamkov