File: parse-orders.pl

package info (click to toggle)
libxml-node-perl 0.11-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 160 kB
  • ctags: 40
  • sloc: perl: 564; xml: 80; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w
use XML::Node;

my $item = "";
my $quantity = "";
my $id = "";
my $date = "";
my $orders = "";

$p = XML::Node->new();

$p->register(">Orders","start" => \&handle_orders_start);
$p->register(">Orders","char" => \$orders);
$p->register(">Orders>Order:ID","attr" => \$id);
$p->register(">Orders>Order:Date","attr" => \$date);
$p->register(">Orders>Order>Item","char" => \$item);
$p->register(">Orders>Order>Quantity","char" => \$quantity);
$p->register(">Orders>Order","end" => \&handle_order_end);
$p->register(">Orders","end" => \&handle_orders_end);

print "Processing file [orders.xml]...\n";
$p->parsefile("orders.xml");

sub handle_orders_start
{
    print "Start of all orders\n-----\n$orders\n----\n";
}

sub handle_order_end
{
    print "Found order [$id] [$date] -- Item: [$item] Quantity: [$quantity]\n";
    $date = "";
    $id="";
    $item = "";
    $quantity = "";
}

sub handle_orders_end
{
    print "End of all orders\n-----\n$orders\n----\n";
}