Gossamer Forum
Home : General : Perl Programming :

script for extracting data from XML file

Quote Reply
script for extracting data from XML file
Hello,
I pretty much a newbie when it comes to code so please go easy on me. Ok, here is what I'm trying to do. I'm running a Jabber (IM) server in Linux RH 8, there is a User Directory that is stored in a XML file called global.xdb. I'm trying to extract the data and post it to a web page. The table shows up with out a hitch the problem is the data is not there. The code below was written by someone else but I can't seem to get in contact with the author.

Here is the code:
Code:
#!/usr/bin/perl -w

use strict;
use warnings;
use CGI qw(:standard);
use XML::Simple;

my $ref = XMLin("/var/www/html/judweb/global.xdb");
my $itemref = $ref->{'foo'}->{'item'};

my $style=<<END;
<!--
A {
COLOR: #ffffff
}
BODY {
FONT-SIZE: 12px;
COLOR: #ffffff;
FONT-FAMILY: Arial, Geneva, Helvetica;
BACKGROUND-COLOR: #000000;
TEXT-ALIGN: left;
TEXT-DECORATION: none;
}
TD {
FONT-SIZE: 12px;
COLOR: #ffffff;
FONT-FAMILY: Arial, Geneva, Helvetica;
TEXT-ALIGN: left;
TEXT-DECORATION: none;
}
-->
END

print header();
print start_html(-title=>"Online Jabber User Directory v1.0", -style=>{-code=>$style});
print "\n\n";
print " <table width=\"100%\">\n";
print " <tr>\n";
print " <td>\n";
print " <br>\n";

foreach my $name (sort keys %{$itemref}) {
my $user = $itemref->{$name};
my $email = $user->{'email'};
my $nick = $user->{'nick'};
my $jid = $user->{'jid'};

print " <table width=\"100%\" border=\"1\">\n";
print " <tr>\n";
print " <td width=\"10%\">Name: </td><td>$name</td>\n";
print " </tr>\n";
print " <tr>\n";
print " <td>Jabber ID: </td><td>$jid</td>\n";
print " </tr>\n";
print " <tr>\n";
print " <td>Nickname: </td><td>$nick</td>\n";
print " </tr>\n";
print " </table>\n";
print " <br>\n";
}

print " </td>\n";
print " </tr>\n";
print " </table>\n";
print "\n";
print end_html();

When I run the script here is the output:

Content-Type: text/html; charset=ISO-8859-1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Online Jabber User Directory v1.0</title>
<style type="text/css">
<!--/* <![CDATA[ */
<!--
A {
COLOR: #ffffff
}
BODY {
FONT-SIZE: 12px;
COLOR: #ffffff;
FONT-FAMILY: Arial, Geneva, Helvetica;
BACKGROUND-COLOR: #000000;
TEXT-ALIGN: left;
TEXT-DECORATION: none;
}
TD {
FONT-SIZE: 12px;
COLOR: #ffffff;
FONT-FAMILY: Arial, Geneva, Helvetica;
TEXT-ALIGN: left;
TEXT-DECORATION: none;
}
-->


/* ]]> */-->
</style>
</head><body>

<table width="100%">
<tr>
<td>
<br>
<table width="100%" border="1">
<tr>
<td width="10%">Name: </td><td>email</td>
</tr>
<tr>
Use of uninitialized value in concatenation (.) or string at ./index.cgi line 54.
<td>Jabber ID: </td><td></td>
</tr>
<tr>
Use of uninitialized value in concatenation (.) or string at ./index.cgi line 57.
<td>Nickname: </td><td></td>
</tr>
</table>
<br>
Argument "\x{47}\x{69}..." isn't numeric in hash element at ./index.cgi line 44.
Bad index while coercing array into hash at ./index.cgi line 44.


Any help would be greatly appriciated. Smile

Eddie
Quote Reply
Re: [HockeyFan] script for extracting data from XML file In reply to
What does your XML file look like?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] script for extracting data from XML file In reply to
Here's the file...