/** * Downloads XML file or returns it from cache * * @param string URL of XML file * @param int Length of time to cache * @return object XML_Tree object */ function retrieveXML($url, $cacheLength, $cacheDir) { include_once 'XML/Tree.php'; if ($data = $this->retrieveFile($url, $cacheLength, $cacheDir)) { $tree = new XML_Tree(); $root =& $tree->getTreeFromString($data); return $root; } return false; }
/** * Creates a treeMenu from XML. The structure of your XML should be * like so: * * <treemenu> * <node text="First node" icon="folder.gif" expandedIcon="folder-expanded.gif" /> * <node text="Second node" icon="folder.gif" expandedIcon="folder-expanded.gif"> * <node text="Sub node" icon="folder.gif" expandedIcon="folder-expanded.gif" /> * </node> * <node text="Third node" icon="folder.gif" expandedIcon="folder-expanded.gif"> * </treemenu> * * Any of the options you can supply to the HTML_TreeNode constructor can be supplied as * attributes to the <node> tag. If there are no subnodes for a particular node, you can * use the XML shortcut <node ... /> instead of <node ... ></node>. The $xml argument can * be either the XML as a string, or an pre-created XML_Tree object. Also, this method * REQUIRES my own Tree class to work (http://phpguru.org/tree.html). If this has not * been include()ed or require()ed this method will die(). * * @param mixed $xml This can be either a string containing the XML, or an XML_Tree object * (the PEAR::XML_Tree package). * @return object The HTML_TreeMenu object */ function createFromXML($xml) { if (!class_exists('Tree')) { die('Could not find Tree class'); } // Supplied $xml is a string if (is_string($xml)) { require_once 'XML/Tree.php'; $xmlTree = new XML_Tree(); $xmlTree->getTreeFromString($xml); // Supplied $xml is an XML_Tree object } else { $xmlTree = $xml; } // Now process the XML_Tree object, setting the XML attributes // to be the tag data (with out the XML tag name or contents). $treeStructure = Tree::createFromXMLTree($xmlTree, true); $treeStructure->nodes->traverse(create_function('&$node', '$tagData = $node->getTag(); $node->setTag($tagData["attributes"]);')); return HTML_TreeMenu::createFromStructure(array('structure' => $treeStructure)); }
require_once('XML/Tree.php'); require_once('Image/Transform.php'); if (@$_POST || @$_GET) { echo "No hacking please"; exit; } $f= $_SERVER['argv'][1]; $exec = "tidy -asxml $f"; $data = `$exec`; /* for debugging - just show it ! */ $tree = new XML_Tree; $tree->getTreeFromString($data); $tree->dump(); class SDX_Parser { var $outputDir = ''; function start($data) { $this->transform($data); // make the subdirectories? $fh = fopen ('slides.xml','w'); fwrite($fh,'<?xml version="1.0" encoding="ISO-8859-1"?>'."\n"); fwrite($fh,"<presentation {$this->presentation}>\n"); fwrite($fh,"<title>{$this->title}</title>\n");
/** * Check if the XML respect the DTD. * Require the XML_DTD package * * @param string $xml The XML text to check * * @return boolean Return true if valid * @access public */ function isValid(&$xml) { $validator = new XML_DTD_XmlValidator(); $tree = new XML_Tree(); $nodes = $tree->getTreeFromString($xml); if (PEAR::isError($nodes)) { return $nodes; } $parser =& new XML_DTD_Parser(); $validator->dtd = $parser->parse($this->_dtd); $validator->_runTree($nodes); if ($validator->_errors) { $errors = $validator->getMessage(); return PEAR::raiseError($errors, XML_FASTCREATE_ERROR_DTD); } return true; }
/** * Import XML text to driver data * * @param string $xml The XML text * * @return object The XML_Tree content * @access public */ function importXML($xml) { $tree = new XML_Tree(); $tree->getTreeFromString($xml); return $tree->root; }