How get cell count and match total column value

Discussion in 'Perl Misc' started by Rahul, Mar 9, 2007.

  1. Rahul

    Rahul Guest

    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
    Rahul, Mar 9, 2007
    #1
    1. Advertising

  2. Rahul <> wrote:

    > 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;
    -----------------------


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Mar 9, 2007
    #2
    1. Advertising

  3. Rahul

    Rahul Guest

    On Mar 9, 5:26 pm, Michele Dondi <> wrote:
    > On 9 Mar 2007 00:39:58 -0800, "Rahul" <>
    > wrote:
    >
    > >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
    Rahul, Mar 10, 2007
    #3
  4. Rahul <> wrote:
    > On Mar 9, 5:26 pm, Michele Dondi <> wrote:
    >> On 9 Mar 2007 00:39:58 -0800, "Rahul" <>
    >> wrote:
    >>


    >> >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.



    > 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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Mar 10, 2007
    #4
  5. On 9 Mar 2007 21:42:04 -0800, "Rahul" <>
    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.

    >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.)

    >$tmp=0;


    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,
    Michele Dondi, Mar 10, 2007
    #5
  6. Rahul

    Rahul Guest

    On Mar 10, 6:30 pm, Michele Dondi <> wrote:
    > On 9 Mar 2007 21:42:04 -0800, "Rahul" <>
    > 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.
    >
    > >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.)
    >
    > >$tmp=0;

    >
    > 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
    Rahul, Mar 12, 2007
    #6
  7. Rahul

    Rahul Guest

    On Mar 12, 12:58 pm, "Rahul" <> wrote:
    > On Mar 10, 6:30 pm, Michele Dondi <> wrote:
    >
    >
    >
    >
    >
    > > On 9 Mar 2007 21:42:04 -0800, "Rahul" <>
    > > 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.

    >
    > > >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.)

    >
    > > >$tmp=0;

    >
    > > 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- Hide quoted text -
    >
    > - Show quoted text -


    Thank you Michel. Many many thanks for quick response. I solved my
    problem. Thanks...thanks...
    Rahul, Mar 12, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    datagrid-how to get cell value(hyperlink column)

    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    8,849
    =?Utf-8?B?UGF1bA==?=
    Oct 13, 2004
  2. thomson
    Replies:
    1
    Views:
    781
    Brock Allen
    Jun 11, 2005
  3. Replies:
    2
    Views:
    1,307
  4. Craig Burkett
    Replies:
    2
    Views:
    601
    Craig Burkett
    Sep 11, 2003
  5. ZyPhiX
    Replies:
    4
    Views:
    85
    ZyPhiX
    Feb 3, 2004
Loading...

Share This Page