473,569 Members | 3,040 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find Missing Column and Extra Column

6 New Member
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
Mar 12 '07 #1
1 1473
docsnyder
88 New Member
@Byomokesh

Assuming @lines contains the lines of your xml file, you could do something like this:

Expand|Select|Wrap|Line Numbers
  1. for ( $i=0 ; $i<=$#lines ; $i++ ) {
  2.   if ( $lines[$i] =~ m(<tgroup\s+cols="(\d+)") ) {
  3.     $numCols = $1;
  4.   }
  5.   elsif ( $lines[$i] =~ m(<row>) ) {
  6.     $colCnt = 0;
  7.     $start  = $i + 1;
  8.   }
  9.   elsif ( $lines[$i] =~ m(</row>) ) {
  10.     if ( $colCnt != $numCols ) {
  11.       printf("lines %d-%d: ERROR: got $colCnt rows (expected: $numCols)\n", $start, $i+1);
  12.       $colCnt = 0;
  13.     }
  14.   }
  15.   elsif ( $lines[$i] =~ m(<entry\s+valign) ) {
  16.     $colCnt++;
  17.   }
  18. }
Greetz, Doc
Mar 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2687
by: Christian Seberino | last post by:
How add a column to a 2d array/matrix in numarray??? The unelegant way I found was to: 1. Create a new array with an extra column (e.g. using 'zeros' function). 2. Copy original array into new array. 3. Copy new column into last column. Is there a slicker way to do this?
0
1180
by: Jack | last post by:
Hi, I got a code that is supposed to build first column as blank and then columns corresponding to the query. However, the final result is coming with one extra column where the vendor code values goes into the extra column while the Vendor Code column is blank. Appreciate any help. Thanks CODE:
2
447
by: John Latten | last post by:
Hi there, I have got a problem when adding extra (= dummy) columns to a datagrid. I have a datagrid that is bound to a datatable. The datatable is filled with data from a SQL Server 2000 database. This data contains a column that is a foreign key to another table. In my datagrid I don't want to display this keyvalue. Instead I want to use...
9
11669
by: Harsha Srinath | last post by:
Athough this might not be directly relayed to C syntax, I thought some of you may find this an interesting problem :- 1.One number, in an array integers from 1 to 1,000,000 is present twice. How can you determine which one? Can you think of a way to do it using little extra memory? 2. How would you find the only missing element in that...
17
3002
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). I have a dataset as follows (1 week to keep it short): Employee 1 - Date 1 Employee 1 - Date 2
67
7632
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 4/30/06 I am looking for suggestions on how to find the date ranges where there were no transactions.
1
1276
by: Fir5tSight | last post by:
Hi All, This seems to be a difficult problem for me. Hope you can help me out... I have a program whose major part is a grid that displays several columns from data obtained from a stored procedure. There is a dialog, and if the user clicks on the "OK" button, an extra column should be appended to the grid. BTW, a separate stored...
6
3078
by: Hemant Shah | last post by:
Folks, Today, I was exporting a table in one database and then importing it in another database. The table in destination database was missing one column (my mistake while creating the table), but import did not complain about it. Source table: Column Type Type
11
10979
by: jennifersalcido | last post by:
Hello All, I am working with two tables that contain inventory data: 1) INVENTORY contains item_number, description, etc. This data is relatively straight-forward, one record per item_number. 2) INV_CROSS_REF contains item_number, and a data column containing either a scancode or a manufacturer part number. The type column indicates...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.