\Xml_writer

Class used to write XMl document.

Extends XMLWriter (PHP5 only!)

Initialize the class: $this->load->library('MY_Xml_writer'); $xml = new MY_Xml_writer; $xml->initiate();

Start a branch with attributes: $xml->startBranch('car', array('country' => 'usa', 'type' => 'racecar'));

End (close) a branch $xml->endBranch();

Add a CDATA node with attributes: $xml->addNode('model', 'Corolla', array('year' => '2002'), true);

Print the XMl directly to screen: $xml->getXml(true);

Pass the XMl to a view file: $data['xml'] = $xml->getXml(); $this->load->view('xml_template', $data);

Summary

Methods
Properties
Constants
__construct()
setRootName()
setXmlVersion()
setCharSet()
setIndentStr()
setXsltFilePath()
initiate()
startBranch()
endBranch()
addNode()
getXml()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_addAttributes()
$_rootName
$_xmlVersion
$_charSet
$_indentString
$_xsltFilePath
N/A

Properties

$_rootName

$_rootName : 

Name of the root element for this XMl. Defaults to root.

Type

$_xmlVersion

$_xmlVersion : 

XML version. Defaults to 1.0

Type

$_charSet

$_charSet : 

Character set. Defaukts to UTF-8.

Type

$_indentString

$_indentString : 

Indent for every new tag. Defaults to spaces.

Type

$_xsltFilePath

$_xsltFilePath : 

Sets an xslt path for this XML. Defaults to ''.

Xslt will only be included in the XML if $_xsltFilePath is not an empty string.

Type

Methods

__construct()

__construct() 

setRootName()

setRootName(  $rootName) 

Set the value of the root tag for this XML

Parameters

$rootName

setXmlVersion()

setXmlVersion(  $version) 

Set the value of the XMl version for this XML.

Parameters

$version

setCharSet()

setCharSet(  $charSet) 

Set the character set for this XML.

Parameters

$charSet

setIndentStr()

setIndentStr(  $indentString) 

Set indenting for every new node in this XML.

Parameters

$indentString

setXsltFilePath()

setXsltFilePath(  $xsltFilePath) 

Set the XSLT filepath for this XML. This should be an absolute URL.

Parameters

$xsltFilePath

initiate()

initiate() 

startBranch()

startBranch(  $name,   $attributes = array()) 

Start a new branch that will contain nodes.

Parameters

$name
$attributes

endBranch()

endBranch() 

End an open branch. A branch needs to be closed explicitely if the branch is followed directly by another branch.

addNode()

addNode(string  $name, string  $value,   $attributes = array(), boolean  $cdata = false) : void

Add a node, typically a child to a branch.

If you wish to create a simple text node, just set $name and $value. If you wish to create a CDATA node, set $name, $value and $cdata. You can set attributes for every node, passing a key=>value $attributes array

Parameters

string $name
string $value
$attributes
boolean $cdata

getXml()

getXml(  $echo = false) : string

Close the XML document, print to screen if $echo == true, and return a string containing the full XML.

Parameters

$echo

Returns

string —
  • The full XML.

_addAttributes()

_addAttributes(array  $attributes) 

Add attributes to an element.

Parameters

array $attributes