Location: PHPKode > projects > Network Asset Management Archive > nama/xmlold.php
<?php

class xItem {
  var $xIP;
  var $xOS;
  var $xHostname;
  var $xServicePack;
}

class xHotfix {
  var $xfix;
}
  

// general vars
$prevTag = "^HOSTS";
$sIP = "";
$sOS = "";
$sHostname = "";
$arItems = array();
$arHotfix = array();
$itemCount = 0;

$uFile = "land.xml";

function startElement($parser, $name, $attrs) {
  global $curTag;

  $curTag .= "^$name";

}

function endElement($parser, $name) {
  global $curTag;

  $caret_pos = strrpos($curTag,'^');

  $curTag = substr($curTag,0,$caret_pos);

}

function characterData($parser, $data) { global $curTag; // get the Channel information first
  global $sTitle, $sLink, $sDescription, $prevTag; 
  $HostKey = "^HOSTS^HOST";
  if ($curTag == $HostKey) {
    $sTitle = $data;
  }
  // now get the items 
  global $arItems, $itemCount,$arHotfix;
  $itemIPKey = "^HOSTS^HOST^IP";
  $itemOSKey = "^HOSTS^HOST^OS";
  $itemHostnameKey = "^HOSTS^HOST^HOSTNAME";
  $itemServicePack = "^HOSTS^HOST^SERVPACK";
  $itemfix = "^HOSTS^HOST^HOTFIXES^HOTFIX";

  if ($curTag == $itemHotfix) {
    $arHotfix[$itemCount] = new xHotfix();
    $arHotfix[$itemCount]->xfix = $data;
  }

  if ($curTag == $itemIPKey) {
    // make new xItem    
    $arItems[$itemCount] = new xItem();     

    // set new item object's properties    
    $arItems[$itemCount]->xIP = $data;
  }
  elseif ($curTag == $itemOSKey) {
    $arItems[$itemCount]->xOS = $data;
  }
  elseif ($curTag == $itemHostnameKey) {
    $arItems[$itemCount]->xHostname = $data;
    // increment item counter
  }
  elseif ($curTag == $itemServicePack) {
    $arItems[$itemCount]->xServicePack = $data;
  }
  if ($curTag == "^HOSTS^HOST") {
    if ($prevTag == "^HOSTS") {
       $itemCount++;
    }
    $prevTag = $curTag;
 }
    $prevTag = $curTag;

print $curTag . "	" . $itemCount . ',' . $data . '<br>';
}

// main loop
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($uFile,"r"))) {
  die ("could not open RSS for input");
}
while ($data = fread($fp, 4096)) {
  if (!xml_parse($xml_parser, $data, feof($fp))) {
    die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
  }
}
xml_parser_free($xml_parser);


// write out the items
?>
<html>
<head>
<title><?php echo ($sTitle); ?></title>
<meta name = "description" content = "<?php echo (count($arItems)); ?>">
</head>
<body bgcolor = "#FFFFFF">
<br>
<table border=1 bgcolor=#ffffcc>
<?php
for ($i=0;$i<count($arItems)+1;$i++) {
  $txItem = $arItems[$i];
        print '<tr><td>';
	echo($txItem->xIP); 
        print '</td><td>';
	echo($txItem->xHostname); 
        print '</td><td>';
	echo ($txItem->xOS); 
        print '</td><td>';
	echo ($txItem->xServicePack); 
//        for ($j=0; $j<count($arHotfix);$j++) {
            $txHotfix = $arHotfix[$i];
            print '</td><td>';
            print $txHotfix->xfix . '- ';
//        }
	print '</td></tr>';

}
echo ("<br>");
?>
</table>
</body>
</html>


Return current item: Network Asset Management Archive