How get cell count and match total column value

R

Rahul

Hi

I am trying to cell count and match in tgroup cols value in XML file
(through perl). if cell count and tgrou cols value is mismatch, its
showing error.

My xml
--------------
<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
<tbody>

If someone could help..

Byomokesh
 
T

Tad McClellan

Rahul said:
I am trying to cell count


There are no cells.

You are trying to column count, I guess.

and match in tgroup cols value in XML file
(through perl). if cell count and tgrou cols value is mismatch, its
showing error.

My xml
--------------
<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
<tbody>


That is not XML.

Where is the endtag for tgroup and tbody?

If someone could help..


You forgot to show us what you have tried so far.

Here's a fish anyway.

-----------------------
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;

my $xml = '<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
</tgroup>';

my $ref = XMLin( $xml );
my $cols = $ref->{cols};
my $colspec = @{ $ref->{colspec} };

print "showing error\n" unless $cols == $colspec;
 
R

Rahul

I am trying to cell count and match in tgroup cols value in XML file
(through perl). if cell count and tgrou cols value is mismatch, its
showing error.
My xml
--------------
<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
<tbody>

This is not your complete xml. Show us a minimal adaptation of it.
Show us also what output you would expect. Better yet: show us what
you've tried thus far and how it fails to work. Without knowing these
details, I may point you to some xml parsing module. If the xml is not
huge and you want something simple, you can try XML::Simple. Otherwise
someone will know better than me.

Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Thanks for reply. Yes i am trying to column count and compare tgroup
cols value. I have a huge xml file. thats why i was not added here. I
want to catch if tgroup cols="3" colspace(column) should be 3. If
colspace should be 4 then showing parse error.

my pl
------

$tmp=0;
print "Enter the filename: ";
chomp($ram=<STDIN>);
open(RED,"$ram.xml");
open(MAD,">$ram.err");
print "WAIT! CHECKING IS IN PROGRESS ..... .....\n";
$cols=0;
while(<RED>)
{
$cou++;

if(/[.,:;!]<\/title>/)

{
print MAD "LINE No. $cou: Trailing punctuations found before </title>
\n";
}

if(/[.,:;?!]<\/mono>/)

{
print MAD "LINE No. $cou: Trailing punctuations found before </mono>
\n";
}

}
close(RED);
close(MAD);

-------------

I am confused how define tgroup cols value and count in
colspace(column) then it is not matching in tgroup cols value, should
be showing error msg. Value is not constant. Because so many tables in
XML files. All tables column is different. If table is 5 column,
tgroup cols="5".

I hope you understand.

Byomokesh
 
T

Tad McClellan

Rahul said:
I have a huge xml file. thats why i was not added here.


Nobody asked for you huge xml file.

Somebody asked for a minimal adaptation of it.

That is, copy and paste (don't retype) just enough to illustrate
the problem that you are trying to solve.

Have you seen the Posting Guidelines that are posted here frequently?
 
M

Michele Dondi

--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

You did better than top-posting, but you'd better go further and trim
down the quoted material to the relevant parts you're commenting only.
In particular you should strip .sig's, well, unless you want to
discuss them, that is.
Thanks for reply. Yes i am trying to column count and compare tgroup
cols value. I have a huge xml file. thats why i was not added here. I

That's why I suggested you to take it and edit it to a bare minimum
still having the charachteristics you need to show what you want.
want to catch if tgroup cols="3" colspace(column) should be 3. If
colspace should be 4 then showing parse error.

my pl
------

No

use strict; # nor
use warnings; # too bad!

(The rationale being: ask perl to give you all the help it can, by
restricting your freedom in ways that will help you to prevent common
programming mistakes.)

Unused variable, and probably no need to initialize it if it were
used.
print "Enter the filename: ";
chomp($ram=<STDIN>);
open(RED,"$ram.xml");

Bareword FH, two-args and unckecked open().

BTW: So is $ram the filename or *part* of it?
open(MAD,">$ram.err");
Ditto.

print "WAIT! CHECKING IS IN PROGRESS ..... .....\n";
$cols=0;

Other unused variable.
while(<RED>)
{
$cou++;

Awkward indenting, bad style.
if(/[.,:;!]<\/title>/)

Attempt at manual XML parsing with regexen: bad! Use some XML parsing
module instead.
{
print MAD "LINE No. $cou: Trailing punctuations found before </title>

So $cou is for counting lines... don't! Just use $. instead. Read
about it in

perldoc perlvar

BTW: warning would better go to STDERR, possibly through the dedicated
warn() function.
if(/[.,:;?!]<\/mono>/)

{
print MAD "LINE No. $cou: Trailing punctuations found before </mono>
\n";

Ditto as above.
close(RED);
close(MAD);

And then?!? I see no attempt at all at checking what you claimed to be
wanting to check.
I am confused how define tgroup cols value and count in
colspace(column) then it is not matching in tgroup cols value, should
be showing error msg. Value is not constant. Because so many tables in
XML files. All tables column is different. If table is 5 column,
tgroup cols="5".

I hope you understand.

Sort of. Without having a *sample* of your actual XML file (not the
whole of it), hard to give even a bare example. But IF the xml is as
regular as the snippet you showed in the last post, then something
just as rude as the following *may* work:


#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
if (/<tgroup\s+cols\s*=\s*"(\d+)">/) {
my ($expected, $found)=$1;
$found++ while <>=~/<colspec/;
warn "Expected $expected cols, found $found at line $.\n"
unless $expected==$found;
}
}

__END__


PLEASE NOTE THAT THIS IS ADMITTEDLY BAD ADVICE AND IF YOU THINK OF
USING SOMETHING LIKE THIS ON A REGULAR BASIS, THEN IT'S LIKELY TO BITE
YOU IN THE NECK.


Michele
 
R

Rahul

--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

You did better than top-posting, but you'd better go further and trim
down the quoted material to the relevant parts you're commenting only.
In particular you should strip .sig's, well, unless you want to
discuss them, that is.
Thanks for reply. Yes i am trying to column count and compare tgroup
cols value. I have a huge xml file. thats why i was not added here. I

That's why I suggested you to take it and edit it to a bare minimum
still having the charachteristics you need to show what you want.
want to catch if tgroup cols="3" colspace(column) should be 3. If
colspace should be 4 then showing parse error.
my pl
------

No

use strict; # nor
use warnings; # too bad!

(The rationale being: ask perl to give you all the help it can, by
restricting your freedom in ways that will help you to prevent common
programming mistakes.)

Unused variable, and probably no need to initialize it if it were
used.
print "Enter the filename: ";
chomp($ram=<STDIN>);
open(RED,"$ram.xml");

Bareword FH, two-args and unckecked open().

BTW: So is $ram the filename or *part* of it?
open(MAD,">$ram.err");
Ditto.

print "WAIT! CHECKING IS IN PROGRESS ..... .....\n";
$cols=0;

Other unused variable.
while(<RED>)
{
$cou++;

Awkward indenting, bad style.
if(/[.,:;!]<\/title>/)

Attempt at manual XML parsing with regexen: bad! Use some XML parsing
module instead.


{
print MAD "LINE No. $cou: Trailing punctuations found before </title>

So $cou is for counting lines... don't! Just use $. instead. Read
about it in

perldoc perlvar

BTW: warning would better go to STDERR, possibly through the dedicated
warn() function.
if(/[.,:;?!]<\/mono>/)
{
print MAD "LINE No. $cou: Trailing punctuations found before </mono>
\n";

Ditto as above.
close(RED);
close(MAD);

And then?!? I see no attempt at all at checking what you claimed to be
wanting to check.
I am confused how define tgroup cols value and count in
colspace(column) then it is not matching in tgroup cols value, should
be showing error msg. Value is not constant. Because so many tables in
XML files. All tables column is different. If table is 5 column,
tgroup cols="5".
I hope you understand.

Sort of. Without having a *sample* of your actual XML file (not the
whole of it), hard to give even a bare example. But IF the xml is as
regular as the snippet you showed in the last post, then something
just as rude as the following *may* work:

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
if (/<tgroup\s+cols\s*=\s*"(\d+)">/) {
my ($expected, $found)=$1;
$found++ while <>=~/<colspec/;
warn "Expected $expected cols, found $found at line $.\n"
unless $expected==$found;
}
}

__END__

PLEASE NOTE THAT THIS IS ADMITTEDLY BAD ADVICE AND IF YOU THINK OF
USING SOMETHING LIKE THIS ON A REGULAR BASIS, THEN IT'S LIKELY TO BITE
YOU IN THE NECK.

Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Thanks for the help. But According to your method i m not getting any
response, when i run this file.

My XML file
------------

<table frame="all" colsep="0" rowsep="0" pgwide="0">
<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
<colspec colnum="4" colname="col4"/> <!-- I want catch this error. Bcz
column is 3 but user define 4 column here -->
<tbody>
<row>
<entry valign="top" align="left"><p><b>nada</b></p></entry>
<entry valign="top" align="left"><p><i>nothing</i></p></entry>
<entry valign="top" align="left"><p>&mdash; No, <b>no</b> hay
<b>nada.</b></p></entry>
</row>
</tbody>
</tgroup>
</table>

Pl file
-------

#!/usr/bin/perl

use strict;
use warnings;

open(FH,"count.xml");
open(MAD,">count.err");
while (<FH>) {
if (/<tgroup\s+cols\s*=\s*"(\d+)">/) {
my ($expected, $found)=$1;
$found++ while <>=~/<colspec/;
warn "Expected $expected cols, found $found at line $.\n"
unless $expected==$found;
}
}

close(FH);
close(MAD);

Please give me complete method. I am very confused.

Byomokesh
 
R

Rahul

On 9 Mar 2007 21:42:04 -0800, "Rahul" <[email protected]>
wrote:
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
You did better than top-posting, but you'd better go further and trim
down the quoted material to the relevant parts you're commenting only.
In particular you should strip .sig's, well, unless you want to
discuss them, that is.
That's why I suggested you to take it and edit it to a bare minimum
still having the charachteristics you need to show what you want.

use strict; # nor
use warnings; # too bad!
(The rationale being: ask perl to give you all the help it can, by
restricting your freedom in ways that will help you to prevent common
programming mistakes.)

Unused variable, and probably no need to initialize it if it were
used.
Bareword FH, two-args and unckecked open().
BTW: So is $ram the filename or *part* of it?
Other unused variable.
Awkward indenting, bad style.
if(/[.,:;!]<\/title>/)

Attempt at manual XML parsing with regexen: bad! Use some XML parsing
module instead.
{
print MAD "LINE No. $cou: Trailing punctuations found before </title>
So $cou is for counting lines... don't! Just use $. instead. Read
about it in
perldoc perlvar
BTW: warning would better go to STDERR, possibly through the dedicated
warn() function.
if(/[.,:;?!]<\/mono>/)
{
print MAD "LINE No. $cou: Trailing punctuations found before </mono>
\n";
Ditto as above.

And then?!? I see no attempt at all at checking what you claimed to be
wanting to check.
Sort of. Without having a *sample* of your actual XML file (not the
whole of it), hard to give even a bare example. But IF the xml is as
regular as the snippet you showed in the last post, then something
just as rude as the following *may* work:

use strict;
use warnings;
while (<>) {
if (/<tgroup\s+cols\s*=\s*"(\d+)">/) {
my ($expected, $found)=$1;
$found++ while <>=~/<colspec/;
warn "Expected $expected cols, found $found at line $.\n"
unless $expected==$found;
}
}

PLEASE NOTE THAT THIS IS ADMITTEDLY BAD ADVICE AND IF YOU THINK OF
USING SOMETHING LIKE THIS ON A REGULAR BASIS, THEN IT'S LIKELY TO BITE
YOU IN THE NECK.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Thanks for the help. But According to your method i m not getting any
response, when i run this file.

My XML file
------------

<table frame="all" colsep="0" rowsep="0" pgwide="0">
<tgroup cols="3">
<colspec colnum="1" colname="col1"/>
<colspec colnum="2" colname="col2"/>
<colspec colnum="3" colname="col3"/>
<colspec colnum="4" colname="col4"/> <!-- I want catch this error. Bcz
column is 3 but user define 4 column here -->
<tbody>
<row>
<entry valign="top" align="left"><p><b>nada</b></p></entry>
<entry valign="top" align="left"><p><i>nothing</i></p></entry>
<entry valign="top" align="left"><p>&mdash; No, <b>no</b> hay
<b>nada.</b></p></entry>
</row>
</tbody>
</tgroup>
</table>

Pl file
-------

#!/usr/bin/perl

use strict;
use warnings;

open(FH,"count.xml");
open(MAD,">count.err");
while (<FH>) {
if (/<tgroup\s+cols\s*=\s*"(\d+)">/) {
my ($expected, $found)=$1;
$found++ while <>=~/<colspec/;
warn "Expected $expected cols, found $found at line $.\n"
unless $expected==$found;
}
}

close(FH);
close(MAD);

Please give me complete method. I am very confused.

Byomokesh- Hide quoted text -

- Show quoted text -

Thank you Michel. Many many thanks for quick response. I solved my
problem. Thanks...thanks...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top