Hi,
I have a problem stripping lines of an xml file.
I have a xml file, were I want to strip of individual tags from the file. My input xml file has lines:
<feedid>2</feedid>
<pagetype>
<action>add</action>
<attribute>freehosting</attribute>
<id>48611</id>
<countryname>
<name>CA</name>
<name>DE</name>
<name>IT</name>
<name>UK</name>
</countryname>
</pagetype>
<pagetype>
<action>add</action>
<attribute>dadsagain</attribute>
<id>29905</id>
<countryname>
</countryname>
</pagetype>
<pagetype>
<action>add</action>
<attribute>trucksboerse</attribute>
<id>48613</id>
<countryname>
<name>DE</name>
</countryname>
</pagetype>
...
My output should skip the attrbutes with no country names and must look like this:
"
ATTRIBUTE: freehosting
NAME: CA, DE, IT ,UK
ATTRIBUTE: trucksboerse
NAME: DE
"
My code is:
# Process the xml feed file
foreach $line (@epifeed)
{
next if ($line =~ m/\<\?xml/);
next if ($line =~ m/pagetype\>/);
next if ($line =~ m/\action\>/);
next if ($line =~ m/page\>/);
next if ($line =~ m/countryname\>/);
if ($line =~ m/\<feedid\>(.*)\<.*$/) {
print Out_customerid_url "\<B\>FEED ID: $1\<\/B\>\n\n" ;
}
if ($line =~ m/\<attribute\>(.*)\<\/.*$/) {
$prev_url = $1;
}
if ($line =~ m/\<name\>(.*)\<\/.*$/) {
if ($1 eq "" {next ;}
else{
print Out3 "\nURL: $prev_url\n" ;
print Out3 "NAME: $1\n";}
}
}
foreach reads eachline of the file, but the problem I have is to be able to print all country names in a single line instead of printing single country name for the attribute many times , my current output is:
"
ATTRIBUTE: freehosting
NAME: CA
ATTRIBUTE: freehosting
NAME: DE
ATTRIBUTE: freehosting
NAME: IT
"
I want to print it as:
"
ATTRIBUTE: freehosting
NAME: CA, DE, IT ,UK
"
How can I do this? Any help will be appreciated.
Thanks,
I have a problem stripping lines of an xml file.
I have a xml file, were I want to strip of individual tags from the file. My input xml file has lines:
<feedid>2</feedid>
<pagetype>
<action>add</action>
<attribute>freehosting</attribute>
<id>48611</id>
<countryname>
<name>CA</name>
<name>DE</name>
<name>IT</name>
<name>UK</name>
</countryname>
</pagetype>
<pagetype>
<action>add</action>
<attribute>dadsagain</attribute>
<id>29905</id>
<countryname>
</countryname>
</pagetype>
<pagetype>
<action>add</action>
<attribute>trucksboerse</attribute>
<id>48613</id>
<countryname>
<name>DE</name>
</countryname>
</pagetype>
...
My output should skip the attrbutes with no country names and must look like this:
"
ATTRIBUTE: freehosting
NAME: CA, DE, IT ,UK
ATTRIBUTE: trucksboerse
NAME: DE
"
My code is:
# Process the xml feed file
foreach $line (@epifeed)
{
next if ($line =~ m/\<\?xml/);
next if ($line =~ m/pagetype\>/);
next if ($line =~ m/\action\>/);
next if ($line =~ m/page\>/);
next if ($line =~ m/countryname\>/);
if ($line =~ m/\<feedid\>(.*)\<.*$/) {
print Out_customerid_url "\<B\>FEED ID: $1\<\/B\>\n\n" ;
}
if ($line =~ m/\<attribute\>(.*)\<\/.*$/) {
$prev_url = $1;
}
if ($line =~ m/\<name\>(.*)\<\/.*$/) {
if ($1 eq "" {next ;}
else{
print Out3 "\nURL: $prev_url\n" ;
print Out3 "NAME: $1\n";}
}
}
foreach reads eachline of the file, but the problem I have is to be able to print all country names in a single line instead of printing single country name for the attribute many times , my current output is:
"
ATTRIBUTE: freehosting
NAME: CA
ATTRIBUTE: freehosting
NAME: DE
ATTRIBUTE: freehosting
NAME: IT
"
I want to print it as:
"
ATTRIBUTE: freehosting
NAME: CA, DE, IT ,UK
"
How can I do this? Any help will be appreciated.
Thanks,