ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/reports/queuegraphing/iscream/XMLParser.pm
Revision: 1.1
Committed: Sun Oct 21 16:52:41 2001 UTC (23 years, 1 month ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Log Message:
An experimental go at using rrdtool to graph i-scream data. Graphing the
Queue's seem like a good idea, as this wasn't done anywhere else. The
README file gives details on how this works.

File Contents

# Content
1 # iscream::XMLParser
2
3 # iscream::XMLParser decodes a string of XML into a
4 # has in a very similar way to the Java version in
5 # the i-scream CMS.
6
7 package iscream::XMLParser;
8
9 use strict;
10 use XML::Parser;
11
12 my @tagstack;
13 my %xmlhash;
14
15 sub parse {
16 my($xml) = @_;
17 %xmlhash = ();
18
19 my $parser = new XML::Parser;
20
21 $parser->setHandlers(Char => \&char_handler,
22 Start => \&start_handler,
23 End => \&end_handler);
24
25 eval { $parser->parse($xml) };
26
27 return ($@, %xmlhash);
28 }
29
30 sub char_handler {
31 my ($p, $value) = @_;
32 &add_value($value);
33 }
34
35 sub start_handler {
36 shift;
37 my($tag) = shift;
38 push(@tagstack, $tag);
39 my($name) = shift;
40 my($val) = shift;
41 while(defined $name && defined $val) {
42 push(@tagstack, "attributes.$name");
43 &add_value($val);
44 pop(@tagstack);
45 $name = shift;
46 $val = shift;
47 }
48 }
49
50 sub end_handler {
51 pop(@tagstack); # safe to not check, parser will do it
52 }
53
54 sub add_value {
55 my($value) = @_;
56 my($tag) = "";
57 foreach my $item (@tagstack) {
58 $tag = $tag . $item . ".";
59 }
60 $tag =~ s/^(.*)\.$/$1/;
61 $xmlhash{$tag} = $value;
62 }
63
64 1;