Login +

Reference Guide / SLS_XMLToolbox

SLS_XMLToolbox1 is a utility class for handling XML.

Accessibility

At Controller level

If you want to enrich the XML stream, you get the current instance SLS_XMLToolbox1 and save at the end of your action :

$xml = $this->getXML();

// Your action code

$this->saveXML($xml);

At Components or Statics level

You work directly with the current reference of SLS_XMLToolbox1 :

$this->_xmlToolBox->addFullTag("key","value",true);

The enhanced information will be stored in the root node //Statics/Site/statics_name/ for a Statics and //Components/Site/component_name/ for a Component.

At other level (PHP)

You can create a new instance of the class :

$xml = new SLS_XMLToolbox();

Construction of nodes

To open a node, simply call the startTag() function:

$xml->startTag("node");
// will produce <node>

To close a node, simply call the endTag() function:

$xml->endTag("node");
// will produce </node>

Finally, to open a node, fill its content and close it, you can call the addFullTag() function:

$xml->addFullTag("node","content",true);
// will produce <node><![CDATA[content]]></node>

The third parameter lets you specify whether you want to protect the contents of the node with CDATA.

Extraction of nodes

Three main functions allow you to make querying xPATH :

- To retrieve a single value

$xml->getTag("//path/to/node[@attribute='value']");

- To retrieve a collection of values

$xml->getTags("//path/to/node[@attribute='value']/childs"); 

- To retrieve a collection of attributes

$xml->getTagsAttributes("//path/to/node",array("atr1","atr2"));

References

  1. SLS_XMLToolbox - Tool SLS_XMLToolbox - XML Treatment