Framework solution
The following sections cover practical implementation details for the topics discussed previously. Again, there is no particular link between the sections.
Reading XML files easily
The hard work of parsing the XML will be done by SimpleXML
, available by default with PHP5. We can wrap it up in a way that makes it easier to use, especially in relation to handling error conditions of various kinds. The basic code that gets the aliroXML
class going is as follows:
class aliroXML { protected $xmlobject = null; protected $maintag = ''; protected $valid = true; public function loadFile ($xmlfile, $attribs=0) { if (!file_exists($xmlfile)) throw new aliroXMLException(sprintf(T_('Requested XML file %s does not exist'), $xmlfile)); if (!is_readable($xmlfile)) throw new aliroXMLException(sprintf(T_('Requested XML file %s is not readable'), $xmlfile)); $string = file_get_contents($xmlfile); return $this->loadString($string, $attribs); } public function loadString ($xmlstring, $attribs...