To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-06-2006, 11:49 AM   #1
vietboy505
Junior Member
 
Join Date: Mar 2006
Posts: 21
[RESOLVED] PERL: XML output to HTML table

I want my PErl to output the content of XML to HTML table like this:

PHP Code:
<table border="1">
<
tr>
<
th>Type</th>
<
th>Contact</th>
</
tr>

<
tr>
<
td>Work</td>
<
td><a href="../search.asp?ID=123456">John Doe</a></td>
</
tr>

<
tr>
<
td></td>
<
td><a href="../search.asp?ID=05789">Jack Doe</a></td>
</
tr>

<
tr>
<
td>Relative</td>
<
td><a href="../search.asp?ID=654321">Jane Doe</a></td>
</
tr>

</
table>
address.xml
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- Comment -->

<Address>
  <Work>
    <JohnDoe>
      <name>John Doe</name>
      <email>john@doe.com</email>
      <phone>555-555-5555</phone>
      <pager>6666666666</pager>
      <id>123456</id>
    </JohnDoe>
    <JackDoe>
      <name>Jack Doe</name>
      <email>jack@doe.com</email>
      <phone>666-666-6666</phone>
      <pager>7777777777</pager>
      <id>05789</id>
    </JackDoe>
  </Work>
  <Relative>
    <JaneDoe>
      <name>Jane Doe</name>
      <email>jane@doe.com</email>
      <phone>444-444-4444</phone>
      <pager>8888888888</pager>
      <id>654321</id>
    </JaneDoe>
  </Relative>
</Address>
address2.pl
PHP Code:
#!/usr/local/bin/perl

print "Content-Type: text/html\n\n";
use
XML::Simple;
use
Data::Dumper;

my $ref = XMLin('address.xml');

print(
'<table border="1">\n
<tr>\n
<th>Type</th>\n
<th>Contact</th>\n
</tr>\n'
);

foreach
my $type (qw(Work Relative)) {
   foreach
my $person (keys %{$ref->{$type}}) {
       
my $id=$ref->{$type}->{$person}->{id};
       
my $name=$ref->{$type}->{$person}->{name};
      print(
"<a href='../search.asp?ID=$id'>$name</a>");
   }
}
print(
'</table>');
I just need how to fix my foreach loop. Any help?
vietboy505 is offline   Reply With Quote
Old 03-07-2006, 06:39 AM   #2
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
Er, are you sure you're in the right place?
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 05:11 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.