Location: PHPKode > projects > Network Asset Management Archive > nama/xml.php
<?$xml_file = "1st3rd.xml";
echo '<body text="#000000" bgcolor="#FFFFCC" link="#0000EE" vlink="#551A8B" alink="#FF0000">';
//echo "<table border=2 bgcolor=#ffffcc>";

function startElement($parser_instance, $element_name, $attrs) {    
global $newrow;
    switch($element_name) {        
    case "IP" :    echo "<td>"; break;
    case "HOSTS" :    echo ""; break;
    case "HOST" :    echo "<table border=2 bgcolor=#ffffcc><TH>HOSTS</TH><th>IP</th><th>OS</th><th>HOSTNAME</th><th>RESOLVED</th><th>USERNAME</th><th>MAC ADDRESS</th><th>LAN MANAGER</th><TH>DOMAIN NAME</th><th>USAGE</th><th>SERVICE PACK</th><th>PDC</th><th>BDC</th><th>TTL</th><th>MASK</th><th>WIN</th><th>RPC</th><th>NMB</th><th>SMB</th><th>reg</th><th>SNMP</th><tr><td>";
foreach ($attrs as $value) {
             echo "$value</td>";
            }
 break;
    case "OS" :    echo "<td>"; break;
    case "ALERTS" :    echo ""; break;
    case "HOSTNAME" :    echo "<td>"; break;
    case "RESOLVED" :    echo "<td>"; break;
    case "MAC" :    echo "<td>"; break;
    case "LANMAN" :    echo "<td>"; break;
    case "USERNAME" :    echo "<td>"; break;
    case "DOMAIN" :    echo "<td>"; break;
    case "SNMPENTRY" :    echo "<tr><td>"; break;
    case "USAGE" :    echo "<td>"; break;
    case "SERVPACK" :    echo "<td>"; break;
    case "PDC" :    echo "<td>"; break;
    case "BDC" :    echo "<td>"; break;
    case "TTL" :    echo "<td>"; break;
    case "MASK" :    echo "<td>"; break;
    case "WIN" :    echo "<td>"; break;
    case "BACKDOORS" :    echo "<td>"; break;
    case "RPC" :    echo "<td>"; break;
    case "NMB" :    echo "<td>"; break;
    case "SMB" :    echo "<td>"; break;
    case "PORTS" :    echo "<table border=2 bgcolor=#FFCCOO><TH>PORTS</TH>"; break;
    case "PORT" :    echo "<tr>";
            foreach ($attrs as $value) {
             echo "<td>$value</td>";
            }
          break;
    case "UDP_PORTS" :    echo "<table border=2 bgcolor=#FFCCCO><TH>UDP PORTS</TH>"; break;
    case "UDP_PORT" :    echo "<tr>";
            foreach ($attrs as $value) {
             echo "<td>$value</td>";
            }
          break;
    case "LINE" :    echo "<td>"; break;
    case "SNMP" :    echo "<table border=2 bgcolor=#cccccc><TH>SNMP</TH>"; break;
    case "NAMES" :    echo "<table border=2 bgcolor=#ccccff><TH>Names</TH>"; 
                      $newrow=1;  
                      break;
    case "NAME" : 
             if ($newrow==1) {
                     echo "<tr>";
             }
            echo "<td>"; 
            foreach ($attrs as $value) {
             echo "<td>$value</td>";
            }
          break;
    case "DOMAINS" :    echo "<td>"; break;
    case "SHARES" :    echo "<table border=2 bgcolor=#646464><TH>SHARES</TH>";
          break;
    case "SHARE" :    echo "<tr>"; 
            foreach ($attrs as $value) {
             echo "<td>$value</td>";
            }
    case "MAIL_ALERTS" :    echo "<table border=2 bgcolor=#747494><TH>MAIL ALERTS</TH>";
          break;
    case "MAIL_ALERT" :    echo "<tr>"; 
            foreach ($attrs as $value) {
             echo "<td>$value</td>";
            }
          break;
    case "GROUPS" :    echo "<table border=2 bgcolor=#929292><TH>GROUPS</TH>"; break;
    case "GROUP" :    echo "<tr><td>"; break;
    case "USERS" :    echo "<table border=2 bgcolor=#F23932><TH>USERS</TH>"; break;
    case "USER" :    echo "<tr><td>"; break;
    case "POLICY" :    echo "<table border=2 bgcolor=#12F932><TH>POLICY</TH>"; break;
    case "POL" :    echo "<tr><td>"; break;
    case "SERVICES" :    echo "<table border=2 bgcolor=#EEEEEE><TH>SERVICE</TH>"; break;
    case "SERVICE" :    echo "<tr><td>"; break;
    case "TRANSPORTS" :    echo "<table border=2 bgcolor=F3F9B0><TH>TRANSPORTS</TH>"; break;
    case "TRANSPORT" :    echo "<tr><td>"; break;
    case "DRIVES" :    echo "<td>"; break;
    case "USES" :    echo "<td>"; break;
    case "PROCESSES" :    echo "<td>"; break;
    case "TOD" :    echo "<table border=2 bgcolor=999999><TH>TIME</TH>"; break;
    case "TOD1" :    echo "<tr><td>"; break;
    case "TOD2" :    echo "<tr><td>"; break;
    case "REGISTRY" :    echo "<table border=2 bgcolor=DDDDDD><TH>REGISTRY</TH>"; break;
    case "REG" :    echo "<tr><td>"; break;
    case "HOTFIXES" :    echo "<table border=2 bgcolor=898989><th>HOTFIXES</th>"; break;
    case "HOTFIX" :    echo "<tr><td>"; break;
    case "CGI_ABUSE" :    echo "<tr>"; break;
    case "CGI_ABUSES" :    echo "<table border=2 bgcolor=#00FF00><TH>CGI_ABUSES</TH>"; break;
    case "BACKDOOR" :    echo "<tr>"; break;
    case "BACKDOORS" :    echo "<table border=2 bgcolor=#00FFFF><TH>BACKDOORS</TH>"; break;
    case "SERVICE_ALERT" :    echo "<tr>"; break;
    case "SERVICE_ALERTS" :    echo "<table border=2 bgcolor=#00FFCC><TH>SERVICE ALERT</TH>"; break;
    case "REGISTRY_ALERT" :    echo "<tr>"; break;
    case "REGISTRY_ALERTS" :    echo "<table border=2 bgcolor=#00CCFF><TH>REGISTRY ALERT</TH>"; break;
    case "INFO_ALERT" :    echo "<tr>"; break;
    case "INFO_ALERTS" :    echo "<table border=2 bgcolor=#FFCCFF><TH>INFO ALERT</TH>"; break;
//    case "NAME" :    echo "<tr><td>" . $attrs[0]; break;
    case "IMPACT" :    echo "<td>"; break;
    case "BUGTRAQ" :    echo "<td>"; break;
    case "DESCR" :    echo "<td>"; break;
    case "MISC_ALERTS" :    echo "<table border=2 bgcolor=#0000ff><TH>MISC_ALERTS</TH>"; break;
    case "MISC_ALERT" :    echo "<tr>"; break;


    default : echo '<b>' . $element_name . '</b>';
    } 
}
    
    
 function characterData($parser_instance, $xml_data) 
 {    
       echo $xml_data;
 } 
 
function endElement($parser_instance, $element_name) {    
global $newrow;
  
switch($element_name) {        
        case "HOSTNAME"   :    echo "</td>"; break;
        case "OS"   :    echo "</td>"; break;
        case "ALERTS"   :    echo ""; break;
        case "IP" :    echo "</td>"; break;
        case "HOSTS" :    echo ""; break;
        case "HOST" :    echo "</tr></table>"; break;
        case "RESOLVED" :    echo "</td>"; break;
        case "MAC" :    echo "</td>"; break;
        case "LANMAN" :    echo "</td>"; break;
        case "USERNAME" :    echo "</td>"; break;
        case "DOMAIN" :    echo "</td>"; break;
        case "SNMPENTRY" :    echo "</td></tr>"; break;
        case "USAGE" :    echo "</td>"; break;
        case "SERVPACK" :    echo "</td>"; break;
        case "PDC" :    echo "</td>"; break;
        case "BDC" :    echo "</td>"; break;
        case "TTL" :    echo "</td>"; break;
        case "BACKDOORS" :    echo "</td>"; break;
        case "MASK" :    echo "</td>"; break;
        case "WIN" :    echo "</td>"; break;
        case "RPC" :    echo "</td>"; break;
        case "NMB" :    echo "</td>"; break;
        case "SMB" :    echo "</td>"; break;
        case "REG" :    echo "</td></tr>"; break;
        case "PORTS" :    echo "</table>"; break;
        case "PORT" :    echo "</tr>"; break;
        case "UDP_PORTS" :    echo "</table>"; break;
        case "UDP_PORT" :    echo "</tr>"; break;
        case "LINE" :    echo "</td>"; break;
        case "SNMP" :    echo "</table>"; break;
	case "NAMES" :    echo "</table>"; 
                          $newrow=0; 
                          break;
	case "NAME" :    echo "</td>"; 
                         if ($newrow==1) {
                              echo "</tr>";
                         }
                         break;
    	case "DOMAINS" :    echo "</td>"; break;
    	case "SHARES" :    echo "</table>"; break;
    	case "SHARE" :    echo "</tr>"; break;
    	case "MAIL_ALERTS" :    echo "</table>"; break;
    	case "MAIL_ALERT" :    echo "</tr>"; break;
    	case "GROUPS" :    echo "</table>"; break;
    	case "GROUP" :    echo "</td></tr>"; break;
    	case "USERS" :    echo "</table>"; break;
    	case "USER" :    echo "</td></tr>"; break;
    	case "POLICY" :    echo "</table>"; break;
    	case "POL" :    echo "</td></tr>"; break;
    	case "SERVICES" :    echo "</table>"; break;
    	case "SERVICE" :    echo "</td></tr>"; break;
    	case "TRANSPORTS" :    echo "</table>"; break;
    	case "TRANSPORT" :    echo "</td></tr>"; break;
    	case "DRIVES" :    echo "</td>"; break;
    	case "USES" :    echo "</td>"; break;
    	case "PROCESSES" :    echo "</td>"; break;
   	case "TOD" :    echo "</table>"; break;
   	case "TOD1" :    echo "</td></tr>"; break;
   	case "TOD2" :    echo "</td></tr>"; break;
    	case "REGISTRY" :    echo "</table>"; break;
    	case "HOTFIXES" :    echo "</table>"; break;
    	case "HOTFIX" :    echo "</td></tr>"; break;
        case "CGI_ABUSE" :    echo "</tr>"; break;
        case "CGI_ABUSES" :    echo "</table>"; break;
        case "BACKDOOR" :    echo "</tr>"; break;
        case "BACKDOORS" :    echo "</table>"; break;
        case "SERVICE_ALERT" :    echo "</tr>"; break;
        case "SERVICE_ALERTS" :    echo "</table>"; break;
        case "REGISTRY_ALERT" :    echo "</tr>"; break;
        case "REGITSTY_ALERTS" :    echo "</table>"; break;
//        case "NAME" :    echo "</td></tr>"; break;
        case "IMPACT" :    echo "</td>"; break;
        case "BUGTRAQ" :    echo "</td>"; break;
        case "DESCR" :    echo "</td>"; break;
        case "MISC_ALERTS" :    echo "</table>"; break;
        case "MISC_ALERT" :    echo "</td>"; break;
    } 
 } 
 
$parser = xml_parser_create();
$newrow=0;
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
if (!($filehandler = fopen($xml_file, "r"))) 
  {    die("could not open XML input");
 }

while ($data = fread($filehandler, 4096)) {    
 if (!xml_parse($parser, $data, feof($filehandler))) {        
      echo "</table>";
      die(sprintf("XML error: %s at line %d",                    
                 xml_error_string(xml_get_error_code($parser)), 
                 xml_get_current_line_number($parser)));
    } 
 }fclose($filehandler);
 xml_parser_free($parser);
echo "</table>";
?>
Return current item: Network Asset Management Archive