Re: [PHP] Can someone help me parse XML? - Challenge

2001-09-18 Thread Christian Reiniger

On Monday 17 September 2001 16:42, Jeff Lewis wrote:
 I have an XML file that I need to parse.  I had the base of a perl
 script written but wasn't completely functioning and was hoping someone
 could give me a hand with making it parse and do what it's supposed to
 but in PHP.  The perl file looked like this:

http://php.net/manual/en/ref.xml.php

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

I sat laughing snidely into my notebook until they showed me a PC running
Linux. And oh! It was as though the heavens opened and God handed down a
client-side OS so beautiful, so graceful, and so elegant that a million
Microsoft developers couldn't have invented it even if they had a hundred
years and a thousand crates of Jolt cola.

- LAN Times

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Can someone help me parse XML? - Challenge

2001-09-17 Thread Jeff Lewis

I have an XML file that I need to parse.  I had the base of a perl script written but 
wasn't completely functioning and was hoping someone could give me a hand with making 
it parse and do what it's supposed to but in PHP.  The perl file looked like this: 

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

$counter = 0;

open (RESUME, resumes.xml);
@resume = RESUME;
close (RESUME);

$resume = join('',@resume);

while ($resume =~ /resume(.*?)\/resume/sg) {

 $counter += 1;
 $myresume = $1;

 $myresume =~ /resumeText(.*)\/resumeText/s;
 $finalresume = $1;
 $finalresume =~ s/\s+$//g;
 $finalresume =~ s/^\s+//g;
 $finalresume =~ s/\n//g;

 $myresume =~ /resumeHolderEntry(.*?)(\/)?/s;
 $resumeholderentry = $1;
 parse($resumeholderentry,'resumeHolderEntry');

 $myresume =~ /resumeEntry(.*?)(\/)?/s;
 $resumeentry = $1;
 parse($resumeentry,'resumeEntry');

}

exit;

sub parse {

 my ($what,$header) = @_;

 $what =~ s/\n//g;
 $what =~ s/^\s+//g;
 $what =~ s/\s+$//g;
 $what =~ s/\s{2}//g;
 $what =~ s/\(.*?)\/\$1\\n/g;

 @pairs = split(/\n/, $what);
 foreach $pair (@pairs) {
  ($name,$value) = split(/=/,$pair);
  $name =~ s/^\s+//g;
  $name =~ s/\s+$//g;
  $value =~ s/\//g;
  $value =~ s/^\s+//g;
  $value =~ s/\s+$//g;

  #push(@temp, $name.'='.$value);
  push(@temp, $value);

 }

 $temp = join('|', @temp);
 if ($header eq resumeEntry) { $temp .= \|$finalresume; }
 open (FILE, $header.txt) or die Can't write to $header: $!;
 print FILE $counter\|$temp\n;
 close (FILE);
}

Now the XML file I can send someone but this is something I should have done from the 
start (use PHP) but now I am out of time and scrambling :(