Project: CONTENIDO Content Management System

Description: The XML writer class of CONTENIDO.

package CONTENIDO Backend Classes
version 1.0.0
author Dominik Ziegler
copyright four for business AG
license http://www.contenido.org/license/LIZENZ.txt
link http://www.4fb.de
link http://www.contenido.org
since file available since CONTENIDO release >= 4.9.0

 Methods

Class constructor of cXmlWriter.

__construct(string $version, string $encoding) : void

Creates the XML document.

Parameters

$version

string

version of XML document (optional, default: 1.0)

$encoding

string

encoding of XML document (optional, default: UTF-8)

Adds a new element to the XML document.

addElement(string $name, string $value, \DOMElement $rootElement, array $attributes) : \DOMElement

If no root element is given the element will be appended to the root node.

Parameters

$name

string

name of the element

$value

string

value of the element (optional)

$rootElement

\DOMElement

root element (optional)

$attributes

array

array of attributes added to this element (optional)

Returns

\DOMElementcreated DOM element

Converts an array to a SimpleXMLElement.

arrayToXml(array $array, \SimpleXMLElement $xml, string $rootTagName) : \SimpleXMLElement
InheritedStatic

Example: array( 'key1' => 'value1', 'key2' => array('value21', 'value22'), 'key3' => array('key31' => 'value31', 'key32' => 'value32') );

becomes

'value1', 'key2' => array('value21', 'value22'), 'key3' => array('key31' => 'value31', 'key32' => 'value32') ); becomes value1 value21 value22 value31 value32

inherited_from \cXmlBase::arrayToXml()

Parameters

$array

array

the array which should be converted to XML

$xml

\SimpleXMLElement

[optional] the element to which the array should be added

$rootTagName

string

[optional] the root tag name which should be used - is only used when $xml is null!

Returns

\SimpleXMLElementthe array as a SimpleXMLElement

Returns the DOMDocument object.

getDomDocument() : \DOMDocument
Inherited
inherited_from \cXmlBase::getDomDocument()

Returns

Returns the encoding of the XML document.

getEncoding() : string
Inherited
inherited_from \cXmlBase::getEncoding()

Exceptions

\cException if there is no DOM document

Returns

stringencoding

Returns given XPath with integrad level definition.

getLevelXpath(string $path, integer $level) : string
InheritedStatic
static
inherited_from \cXmlBase::getLevelXpath()

Parameters

$path

string

XPath to extend

$level

integer

level

Returns

stringextended XPath

registerXpathNamespace()

registerXpathNamespace(string $name, string $value) 
Inherited
inherited_from \cXmlBase::registerXpathNamespace()

Parameters

$name

string

$value

string

Resolves a given path which contains ".

resolvePath(string $path) : string
InheritedStatic

." statement for moving up one level in path.

static
inherited_from \cXmlBase::resolvePath()

Parameters

$path

string

path to resolve

Returns

stringresolved path

Saves the XML tree into a file.

saveToFile(string $directory, string $fileName) : boolean

Parameters

$directory

string

path to destination directory

$fileName

string

name of the written file

Exceptions

\cException if the directory is not writable

Returns

booleanstate of saving process (true if file was created, false otherwise)

Returns the complete XML tree as string.

saveToString() : string

Returns

stringXML tree

Sets a current DOMDocument object to class.

setDomDocument(\DOMDocument $domDocument) : void
Inherited
inherited_from \cXmlBase::setDomDocument()

Parameters

$domDocument

\DOMDocument

DOMDocument object

Converts the given XML string to an array.

xmlStringToArray(string $xmlString) 
InheritedStatic

Example: value1 value21 value22 value31 value32

becomes

array( 'key1' => 'value1', 'key2' => array('value21', 'value22'), 'key3' => array('key31' => 'value31', 'key32' => 'value32') );

inherited_from \cXmlBase::xmlStringToArray()

Parameters

$xmlString

string

contains a valid XML structure

Converts the given SimpleXMLElement object to an array.

xmlToArray(\SimpleXMLElement $xml) 
InheritedStatic

Example: value1 value21 value22 value31 value32

becomes

array( 'key1' => 'value1', 'key2' => array('value21', 'value22'), 'key3' => array('key31' => 'value31', 'key32' => 'value32') );

inherited_from \cXmlBase::xmlToArray()

Parameters

Adds an array of attributes to a specific DOM element.

_addElementAttributes(\DOMElement $element, array $attributes) : \DOMElement
access protected

Parameters

$element

\DOMElement

DOM element to add attributes

$attributes

array

array of attributes

Returns

\DOMElementDOM element with assigned attributes

Creates a new XML document using DOMDocument.

_createDocument(string $version, string $encoding) : void
Inherited
access protected
inherited_from \cXmlBase::_createDocument()

Parameters

$version

string

version of DOMDocument (optional, default: 1.0)

$encoding

string

encoding of DOMDocumen (optional, default: UTF-8)

Initializes a new DOMXPath instance for DOMDocument.

_initXpathInstance() : void
Inherited
inherited_from \cXmlBase::_initXpathInstance()

Exceptions

\cException if there is no valid DOM document

Cleans an array by replacing all empty arrays with empty strings.

_cleanArray(array $array) : array
InheritedStatic

Additionally, the function replaces all associative arrays which have only empty values with the array keys of the array.

inherited_from \cXmlBase::_cleanArray()

Parameters

$array

array

the array to clean

Returns

arraythe cleaned array

 Properties

 

$_dom 
Inherited
inherited_from \cXmlBase::$$_dom
 

$_xpath 
Inherited
inherited_from \cXmlBase::$$_xpath