Sponsored Content
Full Discussion: Perl XML:Parser help
Top Forums Shell Programming and Scripting Perl XML:Parser help Post 302180362 by vincaStar on Monday 31st of March 2008 12:01:57 AM
Old 03-31-2008
Perl XML:Parser help

I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped out for some reason...see code below. Please help.

XML snipit (the target being dropped is highlighted red):
Code:
<Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s23">
   <Font x:Family="Swiss" ss:Size="8.0"/>
  </Style>
  <Style ss:ID="s24">
   <NumberFormat ss:Format="Currency"/>
  </Style>
  <Style ss:ID="s25">
   <NumberFormat ss:Format="&quot;$&quot;#,##0_);[Red]\(&quot;$&quot;#,##0\)"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="256" ss:ExpandedRowCount="994" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="65.0" ss:DefaultRowHeight="12.0">
   <Column ss:AutoFitWidth="0" ss:Width="102.0"/>
   <Column ss:AutoFitWidth="0" ss:Width="53.0"/>
   <Column ss:Width="58.0"/>
   <Column ss:AutoFitWidth="0" ss:Width="53.0" ss:Span="252"/>
   <Row>
    <Cell ss:MergeAcross="2"><Data ss:Type="String">Old Navy - ' Future Football Star' Romper</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">ah1026</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Loved</Data></Cell>
    <Cell ss:Index="3" ss:StyleID="s24"><Data ss:Type="Number">3.0</Data></Cell>
   </Row>




Perl Script:
Code:
use XML::Parser;
$xp=new XML::Parser();
$xp->setHandlers(Start => \&start, End => \&end, Char => \&cdata);
$xp->parsefile("test.xml");

$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>";
}


Last edited by Yogesh Sawant; 03-31-2008 at 01:22 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

xml parser in perl

hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies

2. Shell Programming and Scripting

xml-parser with perl

Hello I want to write an xml- parser with perl an i use the libary XML::LibXML. I have a problem with the command getElementsByTagName. If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero. how can i check if this is a nodelist of lenght zero?? i... (1 Reply)
Discussion started by: trek
1 Replies

3. Shell Programming and Scripting

perl config parser

Hello. Can anybody help me with some sub on perl that can parse config like this: %CFG ( 'databases' => { 'db1' => 'db_11', 'db_12', 'db_13', 'db2' => 'db_21', 'db_22', 'db_23' } 'datafiles' => { 'datadir1' => 'datadir_11', 'datadir_12', 'datadir2' =>... (4 Replies)
Discussion started by: drack
4 Replies

4. UNIX for Advanced & Expert Users

XML parser to generate Tuxedo UD files

Hi, My requirement is like this. I have an XML file which needs to be converted to Tuxedo UD files(param name and param value). Does anybody have a sample perl xml parser script for this? (0 Replies)
Discussion started by: guruprasadpr
0 Replies

5. Shell Programming and Scripting

Facing problem in XML::parser module in PERL

HI, I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out. XML file having characters like: ñ I am... (1 Reply)
Discussion started by: jatanig
1 Replies

6. Shell Programming and Scripting

Where to find 64-bit based perl module like XML::Parser::Expat?

Q: Where to get a 64 bit Expat.so? I run a perl script and got this error: Can't load '/usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/auto/XML/Parser/Expat/Expat.so' for module XML:parser::Expat: ld.so.1:myPerl: fatal:... (0 Replies)
Discussion started by: lilili07
0 Replies

7. Programming

Parser - multiple in Perl

Dear Perl Experts, Could some body help me to find the solution for my problem below: Input file: ----------- THE-0 tsjp THE-32 tsjp THE-64 tsjp Output desired: --------------- THE-0&&-31 tsjp THE-32&&-63 tsjp THE-64&&-95 tsjp Note: 31 = 0+31, (2 Replies)
Discussion started by: askari
2 Replies

8. Shell Programming and Scripting

Help required in Building an XML using SAX Parser in perl

I want to use sax parser for my application as i have 5 Lakhs of data. I have the xml file like this <Nodes> <Node> <NodeName>Company</NodeName> <File>employee_details.csv</File> <data>employee_data.txt</data> <Node> <NodeName>dummy</NodeName> ... (8 Replies)
Discussion started by: vanitham
8 Replies

9. Shell Programming and Scripting

HTML to XML parser

Hello forum, I am having problems to write a bash script. I am trying to get some information from a web page, I want to format it to XMLTV. This is web page: Programación de las cadenas etb1, etb2, etb3, canal vasco y etb sat | EITB Televisión I want to get something like this: <programme... (1 Reply)
Discussion started by: jlazkano
1 Replies

10. Shell Programming and Scripting

Update perl code with parser

The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you :). Most of the data for the parse is included in the document except for the gene and RNA which can is... (0 Replies)
Discussion started by: cmccabe
0 Replies
Parser::Style::Stream(3)				User Contributed Perl Documentation				  Parser::Style::Stream(3)

NAME
XML::Parser::Style::Stream - Stream style for XML::Parser SYNOPSIS
use XML::Parser; my $p = XML::Parser->new(Style => 'Stream', Pkg => 'MySubs'); $p->parsefile('foo.xml'); { package MySubs; sub StartTag { my ($e, $name) = @_; # do something with start tags } sub EndTag { my ($e, $name) = @_; # do something with end tags } sub Characters { my ($e, $data) = @_; # do something with text nodes } } DESCRIPTION
This style uses the Pkg option to find subs in a given package to call for each event. If none of the subs that this style looks for is there, then the effect of parsing with this style is to print a canonical copy of the document without comments or declarations. All the subs receive as their 1st parameter the Expat instance for the document they're parsing. It looks for the following routines: o StartDocument Called at the start of the parse . o StartTag Called for every start tag with a second parameter of the element type. The $_ variable will contain a copy of the tag and the %_ variable will contain attribute values supplied for that element. o EndTag Called for every end tag with a second parameter of the element type. The $_ variable will contain a copy of the end tag. o Text Called just before start or end tags with accumulated non-markup text in the $_ variable. o PI Called for processing instructions. The $_ variable will contain a copy of the PI and the target and data are sent as 2nd and 3rd parameters respectively. o EndDocument Called at conclusion of the parse. perl v5.16.3 2011-05-25 Parser::Style::Stream(3)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy