[Phpxd-commits] CVS: phpXD/samples sample.php,NONE,1.1 sample.xml,NONE,1.1
Status: Beta
Brought to you by:
growbal
From: Thomas D. <th...@us...> - 2002-01-25 22:31:30
|
Update of /cvsroot/phpxd/phpXD/samples In directory usw-pr-cvs1:/tmp/cvs-serv16366/samples Added Files: sample.php sample.xml Log Message: Samples moved from / to /samples. --- NEW FILE: sample.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: sample.php,v 1.1 2002/01/25 22:31:28 thomi Exp $ /** * Sample PHP script for testing phpXD. Loads the file sample.xml and * prints it as HTML. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ require("phpXD.php"); function echoTree(&$dom, $deep = 0) { $space = ""; for ($i = 0; $i < $deep; $i++) $space .= " "; if ($dom->nodeType == CDATA_SECTION_NODE) { echo $space; echo "<span style=\"color:#990000\">"; echo "<![CDATA["; $output = htmlspecialchars($dom->getData()); if (!(strpos($output, "\n") === false)) { $break = "<br />"; } else { $break = ""; $space = ""; } echo $break.$space; $output = str_replace(" ", " ", $output); $output = str_replace("\n", "<br />".$space, $output); $output = str_replace("\t", " ", $output); echo $output; echo $break.$space; echo "]]><br />"; echo "</span>"; } if ($dom->nodeType == COMMENT_NODE) { echo $space; echo "<span style=\"color:#009900\">"; echo "<!--"; $output = htmlspecialchars($dom->getData()); if (!(strpos($output, "\n") === false)) { $break = "<br />"; } else { $break = ""; $space = ""; } echo $break.$space; $output = str_replace(" ", " ", $output); $output = str_replace("\n", "<br />".$space, $output); $output = str_replace("\t", " ", $output); echo $output; echo $break.$space; echo "--><br />"; echo "</span>"; } if ($dom->nodeType == DOCUMENT_NODE) { echo "<pre>"; if (!empty($dom->doctype)) { if (!empty($dom->doctype->publicId) && !empty($dom->doctype->systemId)) { echo "<!DOCTYPE ".$dom->doctype->name." PUBLIC ". $dom->doctype->systemId." ".$dom->doctype->publicId.">\n"; } else { if (!empty($dom->doctype->systemId)) { echo "<!DOCTYPE ".$dom->doctype->name." SYSTEM ". $dom->doctype->systemId.">\n"; } else { $output = $dom->doctype->internalSubset; $output = str_replace("<", "<", $output); $output = str_replace(" > ", "><br />", $output); $output = str_replace("[ ", "[<br />", $output); $output = str_replace("\n", "<br />", $output); echo $output."<br />"; } } } if ($dom->hasChildNodes()) { echoTree($dom->firstChild, $deep); } echoTree($dom->documentElement); echo "</pre>"; } if ($dom->nodeType == DOCUMENT_FRAGMENT_NODE) { echoTree($dom->firstChild); } if ($dom->nodeType == ELEMENT_NODE) { echo $space; echo "<span style=\"color:#000099\">"; echo "<".$dom->tagName; if (isset($dom->attributes)) { for ($i = 0; $i < $dom->attributes->getLength(); $i++) { $elem =& $dom->attributes->item($i); echo " ".$elem->getName()."=\"".$elem->getValue()."\""; } } if ($dom->hasChildNodes()) { echo "><br />"; echo "</span>"; echoTree($dom->firstChild, $deep+4); echo $space; echo "<span style=\"color:#000099\">"; echo "</".$dom->tagName."><br />"; echo "</span>"; } else { echo " /><br />"; echo "</span>"; } } if ($dom->nodeType == TEXT_NODE) { if (trim($dom->getData()) != "") { echo $space; } echo htmlspecialchars(trim($dom->getData())); if (trim($dom->getData()) != "") { echo "<br />"; } } if ($dom->nodeType == PROCESSING_INSTRUCTION_NODE) { echo $space; echo "<span style=\"color:#990099\">"; echo "<?".$dom->getTarget()." "; $output = htmlspecialchars($dom->getData()); $output = trim($output); $output = str_replace(" ", " ", $output); $output = str_replace("\t", " ", $output); if (!(strpos($output, "\n")) === false) { $output = "<br />".$space.$output."<br />".$space; $output = str_replace("\n", "<br />".$space, $output); echo $output; echo "?><br />"; } else { echo $output; echo " ?><br />"; } echo "</span>"; } if (isset($dom->nextSibling)) { echoTree($dom->nextSibling, $deep); } } $parser = new DOMParser(); //echoTree($parser->parseFile("sample.xml")); echoTree($parser->parse("<?xml version=\"1.0\"?><hallo>Thomas</hallo>")); ?> --- NEW FILE: sample.xml --- <?xml version="1.0"?> <hello> This is a phpXD sample dokument. Here are some sample XML features. <a_child> Hello World. </a_child> <an_empty_child /> <!-- This is a comment... --> <![CDATA[ ... and this a CDATA-Section ... ]]> <?php // ... and this a Processing-Instruction echo "PHP is cool"; ?> </hello> |