Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2007, 11:33 PM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in XML parsing

Hi All,

I have to parse on XML file that looks like

<Name>
<Name1>JESSICA HYNES</Name1>
<Name2>DERIK O'BRIEN</Name2>
<Name3>DENZIL</Name3>
</Name>

But when I parse it, I dont get some missing data like

JESSICA HYNES|DERIK|DENZIL

You can see O'BRIEN is missing because of ' I guess

Please give me some solution for this

Denzil

 
Old June 14th, 2007, 10:20 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
quote:
Please give me some solution for this
Show us your code and we might...

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
 
Old April 5th, 2008, 02:01 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Show me your code and we might...



:D


 
Old December 18th, 2008, 03:56 PM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default use this code. i wrote it before long back with out parser. might be useful to you

################################################## #####################
#to parse an xml file #
#model file is given in file.xml #
#file should have only one tag pairs in a line #
################################################## #####################

#!/usr/bin/perl
$filename=$ARGV[0];
open (FILE, "$filename") || die "Can't open $filename : $!\n";
@contents=<FILE>;
close(FILE);
$i=0;
$flag=0;
foreach $line (@contents)
{
$line=~s/>$/ /;
unless($line=~m/(.*>)/)
{
$lonelytag=$line;
$lonelytag=~s/<//;
if($lonelytag=~s/\///)
{

if($flag == 0)
{
print "\n\t$lonelytag\n";
print "@tag\n";
}
print "@value\n";
$i=0;
undef $value;
$flag++;
}

}

else
{
if(($line=~m/(^.*>)(.*<)/))
{
$tag[$i]=$1;
$value[$i]=$2;
$tag[$i]=~s/<//;
$tag[$i]=~s/>/ /;
$value[$i]=~s/<//;
$value[$i]=~s/$/ /;
$i++;
}
}
}
print "\n";


let me kwow if you need any info,
- Nazir





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing the xml which is having vikkiefd XML 14 July 28th, 2008 05:21 AM
parsing xml kri_hegde XML 5 July 24th, 2007 11:37 AM
XML parsing denzil_cactus Perl 0 June 11th, 2007 02:34 AM
XML Parsing Problem when using MSXML magicwanda XML 1 December 9th, 2004 01:56 PM
XML Parsing tgopal Javascript 2 July 27th, 2004 08:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.