<?php

$xml = getXMLFromFile($argv[1]);
$sample = $xml->sample['name'];
$user = $xml->user;
$date = $xml->date;
$db = $xml->db;
$dir = $xml->directory;
$enzyme = $xml->enzyme;
print "Sample {$sample}\n";
print "User {$user}\n";
print "Date {$date}\n";
print "Db {$db}\n";
print "Dir {$dir}\n";
print "Enzyme {$enzyme}\n";
//$arr = xmlObjToArr($xml);
//print_r($arr);
parseXMLObj($xml);
function parseXMLObj($xml)
{
    $name = $xml->getName();
    $val = "";
    if ($name == "reference" || $name == "sequence" || $name == "filename" || $name == "db") {
        if (sizeof($xml->children()) == 0) {
            $val = (string) $xml;
            print " - Value object : {$name} - {$val}\n";
        } else {
            print "\n - Parent object : {$name} - children " . $xml->count() . "\n";
        }
    }
    $attr = (array) $xml->attributes();
if ($help) {
    help(true);
}
if (!is_file($infile)) {
    print "ERROR: No input file given\n";
    help(1);
}
if ($elename == "") {
    print "ERROR: No element name given\n";
    help(1);
}
if ($substring == "") {
    print "ERROR: No filter string given\n";
    help(1);
}
$xml = getXMLFromFile($infile);
print "<interpro_matches>\n";
foreach ($xml->interpro_matches as $match) {
    foreach ($match->protein as $prot) {
        foreach ($prot->interpro as $in) {
            $attr = $in->attributes();
            $name = $attr[$elename];
            if (preg_match("/" . $substring . "/", $name)) {
                print $prot->asXML();
            }
        }
    }
}
print "</interpro_matches>\n";
function getXMLFromFile($infile)
{