Find Missing Column and Extra Column

R

Rahul

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
 
M

Michele Dondi

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
 
H

Henry Law

Rahul said:
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
....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 ...
 
T

Tad McClellan

Rahul said:
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;

}
 
R

Rahul

Rahul said:
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;

}

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
 
J

J. Gleixner

Rahul said:
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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top