crmpicco
11-13-2006, 09:43 AM
These are my files, xmlremove.pl and employees.xml, is there any way to take the value of $xmlnode (i.e. the node number of employee)
and delete that node from the document using Perl?
xmlremove.pl
#! /usr/bin/perl
use CGI;
use XML::Simple;
$cgi = new CGI;
$xml = new XML::Simple;
$xmlnode = $cgi->param('delno');
$xmldata = $xml->XMLin('employees.xml');
print "Content-type: text/html\n\n";
print "XML Node: $xmlnode<br>";
employees.xml
<?xml version='1.0'?>
<staff>
<employee>
<name>
<forename>John</forename>
<surname>Doe</surname>
</name>
<age>
<dob>10-02-1967</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Operations</departmentname>
<title>Manager</title>
</department>
<location>
<town>
<name>Auchinleck</name>
<county>East Ayrshire</county>
</town>
</location>
</employee>
<employee>
<name>
<forename>Craig R.</forename>
<surname>Morton</surname>
</name>
<age>
<dob>05-03-1984</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Internet</departmentname>
<title>Developer</title>
</department>
<location>
<town>
<name>Ayr</name>
<county>South Ayrshire</county>
</town>
</location>
</employee>
<employee>
<name>
<forename>William</forename>
<surname>McCann</surname>
</name>
<age>
<dob>15-07-1982</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Sales</departmentname>
<title>Executive</title>
</department>
<location>
<town>
<name>Kilmarnock</name>
<county>North Ayrshire</county>
</town>
</location>
</employee>
</staff>
and delete that node from the document using Perl?
xmlremove.pl
#! /usr/bin/perl
use CGI;
use XML::Simple;
$cgi = new CGI;
$xml = new XML::Simple;
$xmlnode = $cgi->param('delno');
$xmldata = $xml->XMLin('employees.xml');
print "Content-type: text/html\n\n";
print "XML Node: $xmlnode<br>";
employees.xml
<?xml version='1.0'?>
<staff>
<employee>
<name>
<forename>John</forename>
<surname>Doe</surname>
</name>
<age>
<dob>10-02-1967</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Operations</departmentname>
<title>Manager</title>
</department>
<location>
<town>
<name>Auchinleck</name>
<county>East Ayrshire</county>
</town>
</location>
</employee>
<employee>
<name>
<forename>Craig R.</forename>
<surname>Morton</surname>
</name>
<age>
<dob>05-03-1984</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Internet</departmentname>
<title>Developer</title>
</department>
<location>
<town>
<name>Ayr</name>
<county>South Ayrshire</county>
</town>
</location>
</employee>
<employee>
<name>
<forename>William</forename>
<surname>McCann</surname>
</name>
<age>
<dob>15-07-1982</dob>
</age>
<sex>M</sex>
<department>
<departmentname>Sales</departmentname>
<title>Executive</title>
</department>
<location>
<town>
<name>Kilmarnock</name>
<county>North Ayrshire</county>
</town>
</location>
</employee>
</staff>