Perl & XML... Need help.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl & XML... Need help.
# 1  
Old 03-31-2008
Perl & XML... Need help.

In the case that there are two cells under one row, I can only read the first cell. If anyone thinks they know how to deal with this please let me know.

XML code:
<Row>
<Cell><Data ss:Type="String">Loved</Data></Cell>
<Cell ss:Index="3"><Data ss:Type="Number">3.0</Data></Cell>
</Row>
<Row>
<Cell ss:MergeAcross="1"><Data ss:Type="String">12-18 months</Data></Cell>
</Row>


Perl code:
use XML::Parser;
$xp=new XML::Parser();
$xp->setHandlers(Start => \&start, End => \&end, Char => \&cdata);
$xp->parsefile("test.xml");
$flag=$hst=$hster=$hsted=0;
$manu=$prod=$image=$desc=$price=$cat=0;
$ctag=0;
sub start(){
my ($p, $name, %attr) = @_;
$ctag = lc($name);
}
sub cdata(){
my ($parser, $target, $data) = @_;
if (lc($target) == "cell"){
if (($target=~/\w|\d/) && ($target ne "False") && ($target !~ /#/)){
push @array, $target;
}
}
}
sub end(){
my ($p, $name) = @_;
$ctag = lc($name);
}
foreach $a (@array){
print $a."<br>";
}



OUTPUT:
Loved
12-18 months
# 2  
Old 03-31-2008
You should use the warnings pragam with your script:

use warnings;

I am pretty sure it would have alerted you to this problem:

if (lc($target) == "cell"){

"==" is the wrong operator, maybe you mean to use "eq" instead:

if (lc($target) eq "cell"){

I am pretty sure the way you have it "cell" will be avaluated as 0 (zero)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want replace string <enclosure>&#x22;</enclosure> with <enclosure>&#x5e;</enclosure> in xml

I have xml files with with extension .ktr in subfolders i want to replace the string <enclosure>&#x22;</enclosure> with <enclosure>&#x5e;</enclosure> i have written logic but it is not working correctly sed -i '' 's#<enclosure>&\#x22;</enclosure>#<enclosure>&\#x5e;</enclosure>#g' *.ktr ... (3 Replies)
Discussion started by: reddy12
3 Replies

2. Shell Programming and Scripting

XML files with spaces in the tag name, parse & display?

Greetings all, I have an XML file that is being generated from my application, here is a sample of the first tag (That I am trying to remove and display in a list..) Example- <tag one= "data" data="1234" updateTime="1300"> <tag one= "data1" data="1234" updateTime="1300"> <tag... (5 Replies)
Discussion started by: jeffs42885
5 Replies

3. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

4. Programming

Java & XML

Hi all, I am new to Java and XML. Please let me know where to start and after some search SAX is very easy as it covers only part of the xml files we need to handle. Give me some Tutorial links on Java+XML using SAX. Thanks. (0 Replies)
Discussion started by: gameboy87
0 Replies

5. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

6. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

7. Shell Programming and Scripting

XML Copy & replace problem

I probably could have done this at one time, but, the years and no need has left my scripting skills lacking and I'm unable to work this problem out. https://www.unix.com/images/smilies/frown.gif :( Using Linux, have a great many xml files in which there may be multiple occurrence of a line of... (13 Replies)
Discussion started by: xenixuser
13 Replies

8. SCO

XML Import & HTTP Post

this may be very basic to some but all new to me I have an application running on SCO Unix server which issues an HTTP Post request to a server with the results being returned in I.E browser window in XML format I need to import these results into my customers application and dont know how to... (1 Reply)
Discussion started by: ccarcher
1 Replies

9. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

10. Shell Programming and Scripting

HTTP Query Request & Parsing returned XML output

I have a PERL script from which I need to make a HTTP request to Web Servlet (Essentially a URL with variables and values like &Variable1=AAAAAA&Variable2=BBBBBBBBB&Variable3=CCCCCCC). The Web servlet returns an XML result which needs to be parsed for the contents of the result within the program.... (15 Replies)
Discussion started by: jerardfjay
15 Replies
Login or Register to Ask a Question