Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Find Missing Column and Extra Column

Reply
Thread Tools

Find Missing Column and Extra Column

 
 
Rahul
Guest
Posts: n/a
 
      03-12-2007
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

 
Reply With Quote
 
 
 
 
Michele Dondi
Guest
Posts: n/a
 
      03-12-2007
On 12 Mar 2007 03:31:29 -0700, "Rahul" <(E-Mail Removed)>
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,
 
Reply With Quote
 
 
 
 
Henry Law
Guest
Posts: n/a
 
      03-12-2007
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:arser. "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:arser

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:arser. 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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-12-2007
Rahul <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Rahul
Guest
Posts: n/a
 
      03-17-2007
On Mar 13, 4:25 am, Tad McClellan <(E-Mail Removed)> wrote:
> Rahul <(E-Mail Removed)> 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
> (E-Mail Removed) 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

 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      03-19-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
Serial ata PCI card, that XP can find while installing with no extra driver? kenny Computer Support 1 10-25-2005 03:28 AM
Extra column is getting built Jack ASP General 0 09-16-2004 05:57 PM



Advertisments