#!/usr/bin/perl
use strict;
use IO;


# Open XML File
# $indent = xml_open_file($fh,$name)
sub xml_open_file
{
my $indent = 0;

    # Grab Arguments
    my $fh = shift;
    my $name = shift;

    # Open An XML File
    if(!$fh->open("> $name.xml")) {
        print "Unable To Open File $name.xml\n";
        exit(1);
        }

    my $indent = xml_write_open_tag($fh,$indent,"opt");
    return $indent;
}
1;

# Close XML File
# $indent = xml_close_file($fh)
sub xml_close_file
{
my $indent = 0;

    # Collect Arguments
    my $fh = shift;

    $indent = xml_write_close_tag($fh,$indent,"opt");
    $fh->close();
    return $indent;
}

# Write <tag><field></tag>
# $indent = xml_write_field($fh,$indent,$tag,$field)
sub xml_write_field
{
    # Collect Arguments
    my $fh = shift;
    my $indent = shift;
    my $tag = shift;
    my $field = shift;

    xml_write_indent($fh,$indent);
    $fh->print("\<$tag\>$field\</$tag\> \n");
    return $indent;
}

# Write <tag>
# $indent = xml_write_open_tag($fh,$indent,$tag)
sub xml_write_open_tag
{
    # Collect Arguments
    my $fh = shift;
    my $indent = shift;
    my $tag = shift;

    xml_write_indent($fh,$indent);
    $fh->print("\<$tag\> \n");
    $indent++;
    return $indent;
}

# Write </tag>
# $indent = xml_write_close_tag($fh,$indent,$tag)
sub xml_write_close_tag
{
    # Collect Arguments
    my $fh = shift;
    my $indent = shift;
    my $tag = shift;

    $indent--;
    xml_write_indent($fh,$indent);
    $fh->print("\</$tag\> \n");
    return $indent;
}

# Write Indent
# xml_write_indent($fh,$indent)
sub xml_write_indent
{
my $i;

    # Collect Arguments
    my $fh = shift;
    my $indent = shift;

    for($i = 0;$i < $indent;$i++) {
        $fh->print("  ");
        }
}

