ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/reports/graphing/iscream/XMLParser.pm
Revision: 1.1
Committed: Sat Mar 9 19:53:24 2002 UTC (22 years, 8 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
Graphing of most of the i-scream data. This is intended as an alternative
to the current MySQL/DBReporter style of daily graph generation.
This is split into two sections:
watch.pl connects to the i-scream client interface, parses all the data
and stores it in rrdtool database files. This is still very incomplete and
somewhat messy code :)
graph.pl generates graphs from the rrdtool database files created by the
previous script. It drops these images into a directory structure for
viewing over the web.
The php pages provide an easy way to view these graphs during development,
but it is expected in the long term to integrate this into the i-scream
reports pages.
Finally XMLParser.pm is a wrapper to the XML parsing to create i-scream
style XMLPacket hashes :)

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;