cXmlReader & cXmlWriter

cXmlReader & cXmlWriter classes provides xml handling in CONTENIDO. This  classes should be used for all xml read and write purposes in CONTENIDO.

cXmlReader

The reader class should be used for all read only xml operations.

Just create cXmlReader instance and call loadXML or load methods(see code below).

The difference in this methods is simple. The load method loads xml from file and loadXML loads xml from given string.

$pathToXml = "path/to/some/xml/file/example.xml";
$xmlAsString = "<?xml version="1.0" encoding="UTF-8"?>...";

$xmlReader = new cXmlReader();

$domDocument = $xmlReader->loadXML($xmlAsString);
or
$domDocument = $xmlReader->load($pathToXml);

cXmlReader class provides also some helpful xpath methods.

$xmlReader->getXpathNodeList($xPathString);
$xmlReader->getXpathNode($xPathString);
$xmlReader->getXpathValue($xPathString);
$xmlReader->countXpathNodes($xPathString);

cXmlWriter

The writer class should be used for all write XML operations. Just create a cXmlWriter instance.

$writer = new cXmlWriter();

By default is the XML version 1.0 and encoding UTF-8. If you want to use another XML version or encoding, then you may specify these in the constructor.

$writer = new cXmlWriter($version, $encoding);

After creation of writer object you can call addElement method. This method adds new node to the created XML document. First parameter is the name of the node element. This parameter is obligatory, all other parameters are optional.

$elem = $writer->addElement($name[, $value[, $parent[, $attr[, $cdata]]]]);

After creation and adding of elements to the created XML file, you can save it. For saving purposes you can use two different functions, saveToString and saveToFile. The saveToString method returns whole XML file as string and saveToFile method gives you possibility to save xml as file in the directory on the file system.

$xml = $writer->saveToString();
$writer->saveToFile($directory, $filename);