Find Missing Column and Extra Column

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

  1. Rahul

    Rahul Guest

    Hi All,

    This XML file is 2 errors. My table is 3 columns. One is extra column
    and another is missing one columne. How i will find those error
    through perl script.

    XML file
    ------------
    <table>
    <tgroup cols="3">
    <colspec colnum="1" colname="col1"/>
    <colspec colnum="2" colname="col2"/>
    <colspec colnum="3" colname="col3"/>
    <tbody>
    <row>
    <entry valign="top" align="left"><p>nada</p></entry>
    <entry valign="top" align="left"><p>nothing</p></entry>
    <entry valign="top" align="left"><p>nada.</p></entry>
    <entry valign="top" align="left"><p></p></entry> <!-- One Row Extra
    Here -->
    </row>
    <row>
    <entry valign="top" align="left" namest="col1"
    nameend="col2"><p>centra</p></entry>
    <!-- One row is missing here -->
    </row>
    </tbody>
    </tgroup>
    </table>

    Thanks for any help.
    Byomokesh
     
    Rahul, Mar 12, 2007
    #1
    1. Advertising

  2. On 12 Mar 2007 03:31:29 -0700, "Rahul" <>
    wrote:

    >This XML file is 2 errors. My table is 3 columns. One is extra column
    >and another is missing one columne. How i will find those error
    >through perl script.


    Why do you think that reposting what's basically the same question
    discussed in another thread as a new one is going to help you?


    PS: well done, eventually preparing a reasonably complete xml
    example...


    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 12, 2007
    #2
    1. Advertising

  3. Rahul

    Henry Law Guest

    Rahul wrote:
    > Hi All,
    >
    > This XML file is 2 errors. My table is 3 columns. One is extra column
    > and another is missing one columne. How i will find those error
    > through perl script.
    >
    > XML file
    > ------------
    > <table>
    > <tgroup cols="3">
    > <colspec colnum="1" colname="col1"/>

    ....etc

    Let me help you help yourself in future. If you must use Perl to do
    this task then ask yourself how the language might help; when you
    understand the answer to that question then you'll be much further on
    and will be able to ask a question in this group which the experts here
    (of whom I am not one) can answer.

    If Perl is going to help then either
    (1) Perl has XML table-parsing capability itself, built-in; or
    (2) Perl has some additional stuff you can install which has that
    capability; or
    (3) Perl itself has no capability to do that but provides facilities
    with which you can write the program yourself.

    If (1) is true then a Perl manual or help-site will provide some
    information. In fact, Perl has a help mode which is quite useful. Try

    perldoc -h

    at a command line. That will lead you to "perldoc -q XML", maybe, from
    which you'll find that the Perl FAQ contains no FAQs to do with XML.
    Doesn't look good for Perl having XML capability.

    So maybe (2) is true. Have you tried Googling for (say) "Perl XML
    parse"? You'll get lots of hits with entries talking about modules,
    including XML::Simple, XML::parser. "What's a module?" I hear you say.
    Well perldoc will help you ...

    perldoc -q module

    .... that should lead you to

    perldoc XML::Simple
    perldoc XML::parser

    At that point you will realise that (3) is in fact the one that's true:
    Perl provides assistance in XML parsing but you need to write the
    program. Start messing about (yes, write some Perl code!) with
    XML::Simple or XML::parser. You'll get totally confused, at which
    point post here. We'll help. We just won't do your work for you.
    (Except I just have - some of it at any rate).

    But, as others have pointed out, Perl may not be the handiest way of
    doing what you want; there are other XML-specific products that might be
    more effective. But I smell homework ...

    --

    Henry Law Manchester, England
     
    Henry Law, Mar 12, 2007
    #3
  4. Rahul <> wrote:

    > My table is 3 columns.


    ><tgroup cols="3">


    ><row>
    ><entry valign="top" align="left" namest="col1"
    > nameend="col2"><p>centra</p></entry>
    ><!-- One row is missing here -->



    I thought you said it was supposed to contain 3 columns?

    There are *two* rows missing there then. Right?

    You forgot yet again so show us what you have tried so far.


    > Thanks for any help.



    Thanks for ignoring the help provided to you earlier.

    Have another fish along with your scorefile entry:


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

    my $xml = '
    <table>
    <tgroup cols="3">
    <colspec colnum="1" colname="col1"/>
    <colspec colnum="2" colname="col2"/>
    <colspec colnum="3" colname="col3"/>
    <tbody>
    <row>
    <entry valign="top" align="left"><p>nada</p></entry>
    <entry valign="top" align="left"><p>nothing</p></entry>
    <entry valign="top" align="left"><p>nada.</p></entry>
    <entry valign="top" align="left"><p></p></entry> <!-- One Row Extra Here -->
    </row>
    <row>
    <entry valign="top" align="left" namest="col1" nameend="col2"><p>centra</p></entry>
    <!-- One row is missing here -->
    </row>
    </tbody>
    </tgroup>
    </table>
    ';

    my $ref = XMLin( $xml, ForceArray => ['entry'] );
    my $cols = $ref->{tgroup}{cols};

    my $row_cnt=0;
    foreach my $row ( @{ $ref->{tgroup}{tbody}{row} } ) {
    my $col_cnt = @{ $row->{entry} };
    print "line ", ++$row_cnt, " has $col_cnt columns\n" unless $cols == $col_cnt;

    }
    ----------------------------


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 12, 2007
    #4
  5. Rahul

    Rahul Guest

    On Mar 13, 4:25 am, Tad McClellan <> wrote:
    > Rahul <> wrote:
    > > My table is 3 columns.
    > ><tgroup cols="3">
    > ><row>
    > ><entry valign="top" align="left" namest="col1"
    > > nameend="col2"><p>centra</p></entry>
    > ><!-- One row is missing here -->

    >
    > I thought you said it was supposed to contain 3 columns?
    >
    > There are *two* rows missing there then. Right?
    >
    > You forgot yet again so show us what you have tried so far.
    >
    > > Thanks for any help.

    >
    > Thanks for ignoring the help provided to you earlier.
    >
    > Have another fish along with your scorefile entry:
    >
    > ----------------------------
    > #!/usr/bin/perl
    > use warnings;
    > use strict;
    > use XML::Simple;
    >
    > my $xml = '
    > <table>
    > <tgroup cols="3">
    > <colspec colnum="1" colname="col1"/>
    > <colspec colnum="2" colname="col2"/>
    > <colspec colnum="3" colname="col3"/>
    > <tbody>
    > <row>
    > <entry valign="top" align="left"><p>nada</p></entry>
    > <entry valign="top" align="left"><p>nothing</p></entry>
    > <entry valign="top" align="left"><p>nada.</p></entry>
    > <entry valign="top" align="left"><p></p></entry> <!-- One Row Extra Here -->
    > </row>
    > <row>
    > <entry valign="top" align="left" namest="col1" nameend="col2"><p>centra</p></entry>
    > <!-- One row is missing here -->
    > </row>
    > </tbody>
    > </tgroup>
    > </table>
    > ';
    >
    > my $ref = XMLin( $xml, ForceArray => ['entry'] );
    > my $cols = $ref->{tgroup}{cols};
    >
    > my $row_cnt=0;
    > foreach my $row ( @{ $ref->{tgroup}{tbody}{row} } ) {
    > my $col_cnt = @{ $row->{entry} };
    > print "line ", ++$row_cnt, " has $col_cnt columns\n" unless $cols == $col_cnt;
    >
    > }
    >
    > ----------------------------
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas


    I am getting "Unrecognised option: ForceArray at cellcount.pl line
    27". I have installed XML:Simple. What is the reason for this errors?


    Thanks
    Byomokesh
     
    Rahul, Mar 17, 2007
    #5
  6. Rahul

    J. Gleixner Guest

    Rahul wrote:

    > I am getting "Unrecognised option: ForceArray at cellcount.pl line
    > 27". I have installed XML:Simple. What is the reason for this errors?


    How the heck is anyone supposed to know, without any code?

    If you're following the documented way of using XML::Simple, then you
    must have an error around line 27.
     
    J. Gleixner, Mar 19, 2007
    #6
    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. Gary Herron
    Replies:
    2
    Views:
    681
    Bruno Desthuilliers
    Jul 4, 2006
  2. mathieu
    Replies:
    3
    Views:
    608
    Bo Persson
    Sep 4, 2009
  3. Jack

    Extra column is getting built

    Jack, Sep 16, 2004, in forum: ASP General
    Replies:
    0
    Views:
    140
  4. Wybo Dekker
    Replies:
    1
    Views:
    379
    Yukihiro Matsumoto
    Nov 15, 2005
  5. vdvorkin
    Replies:
    0
    Views:
    423
    vdvorkin
    Feb 10, 2011
Loading...

Share This Page