Basic Usage of XML_FOAF_Parser
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>XML_FOAF_Parser Example</title> 5 <meta name="Author" content="" /> 6 <meta name="Keywords" content="" /> 7 <meta name="Description" content="" /> 8 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 9 <style type="text/css"> 10 table,th,td { border: 1px solid black; } 11 </style> 12 </head> 13 <body> 14 <?php 15 // Get our FOAF File from $_GET['foaf'] 16 if (!isset($_REQUEST['foaf'])) { 17 echo "<strong>Please enter a FOAF file below"; 18 } else { 19 $foaf = file_get_contents($_REQUEST['foaf']); 20 21 // Require the XML_FOAF_Parser class 22 require_once 'XML/FOAF/Parser.php'; 23 24 // Create new Parser object 25 $parser = new XML_FOAF_Parser; 26 27 // Start of output 28 echo '<h1>XML_FOAF_Parser Example</h1>'; 29 if (isset($_REQUEST['xml'])) { 30 echo '<pre>' .htmlentities($foaf). '</pre>'; 31 } 32 33 // Parser our FOAF in $foaf 34 $parser->parseFromMem($foaf); 35 36 if (isset($_REQUEST['table'])) { 37 // Show our FOAF as an HTML table 38 echo "<h2>FOAF as HTML Table</h2>"; 39 echo $parser->toHTML($parser->toArray()); 40 } 41 42 if (isset($_REQUEST['array'])) { 43 // Show the contents of the FOAF Data array 44 echo "<h2>FOAF as Array</h2>"; 45 echo "<pre>"; 46 var_dump($parser->toArray()); 47 echo "</pre>"; 48 } 49 } 50 ?> 51 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 52 <p> 53 <label>FOAF File URI: <input type="text" name="foaf" value="<?php echo(@$_REQUEST['foaf']) ?>" /></label> 54 <br /> 55 Show XML: <input type="checkbox" name="xml" value="true" /> 56 <br /> 57 Show as HTML Table: <input type="checkbox" name="table" value="true" checked="checked" /> 58 <br /> 59 Show as Array: <input type="checkbox" name="array" value="true" /> 60 <br /> 61 <input type="submit" value="Parse FOAF!" /> 62 </p> 63 </form> 64 </body> 65 </html>
|