473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Wtd: HTML editor to swap the order of columns in tables


I have an HTML document which has a long table, with five columns.

I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?

(Cross-posted; comp.infosystems.www.authoring.html used, as I don't
receive comp.infosystems.www.authoring.tools)

--
Andy Mabbett
Say "NO!" to compulsory ID Cards: <http://www.no2id.net/>

Free Our Data: <http://www.freeourdata.org.uk>
Aug 27 '06 #1
8 2032
Andy Mabbett wrote:
>
I have an HTML document which has a long table, with five columns.

I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?
Yes. It's called a "Regular Expression Processor", and it is part of most
modern programming languages.

Untested example script (Ruby):

-------------------------------

#!/usr/bin/ruby -w

data = STDIN.read

data.gsub!(%r{(<tr><td>.*?</td><td>.*?</td><td>.*?</td>)(<td>.*?</td>
(<td>.*?</td>)}m,"\\1\\3\\2")

puts data

------------------------------

Use:

scriptname < input.file output.file

Or, you could download my freeware HTML workshop Arachnophilia and write the
above regular expression into its search/replace window. That would be
easier for an end user, while the above Ruby script is easier and more
flexible (will process any number of files by simply naming them) for a
more advanced computer user.

In the long term, it is much more productive to learn how to process HTML
using scripts that contain regular expressions.

Arachnophilia:

http://www.arachnoid.com/arachnophilia/index.html

--
Paul Lutus
http://www.arachnoid.com
Aug 27 '06 #2
On 2006-08-27 07:05:54 -0400, Andy Mabbett
<us**********@pigsonthewing.org.uksaid:
>
I have an HTML document which has a long table, with five columns.

I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?

(Cross-posted; comp.infosystems.www.authoring.html used, as I don't
receive comp.infosystems.www.authoring.tools)
If you're not comfortable with RegEx/perl/scripting etc (many aren't)
then DreamWeaver will do this with a simple 'Cut/Paste' option.

Might be an easier way to go.

Ben

Aug 27 '06 #3
AES
In article <Gd**************@pigsonthewing.org.uk>,
Andy Mabbett <us**********@pigsonthewing.org.ukwrote:
I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?
Excel? (or other low cost spreadsheet)
Aug 27 '06 #4
JRS: In article <Gd**************@pigsonthewing.org.uk>, dated Sun, 27
Aug 2006 12:05:54 remote, seen in news:comp.infosystems.www.authoring.html,
Andy Mabbett <us**********@pigsonthewing.org.ukposted :
>
I have an HTML document which has a long table, with five columns.

I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?
Much depends on whether the layout of the source is consistent. If all
columns of a row are in a single source line, no problem; if they're
split in a consistent manner, no great problem; if the table code is
wrapped like a paragraph of text without regard to its HTML structure,
then why not fix that first? ISTM MiniTrue will do it.

For the first case, start with something like (partly tested) :

mtr -x+ u*.htm "(.*<\/td>)(.*<\/td>)(.*<\/td>)(.*<\/td>)(.*<\/td>)" = \1\2\3\5\4

AFTER reading mtr -h & mtr -? completely.

NOTE that to involve \1 in the reordering a change may be needed; consider

mtr -x+ u*.htm "(<td>.*)(<td>.*)(<td>.*)(<td>.*)(<td>.*)" = \2\3\1\4\5

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/>
Aug 28 '06 #5
Paul Lutus <no****@nosite.zzzwrites:
Andy Mabbett wrote:
I have an HTML document which has a long table, with five columns.

I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?

Yes. It's called a "Regular Expression Processor", and it is part of most
modern programming languages.
....and they're really tricky to get right on non-trivial HTML.
data.gsub!(%r{(<tr><td>.*?</td><td>.*?</td><td>.*?</td>)(<td>.*?</td>
(<td>.*?</td>)}m,"\\1\\3\\2")
Consider trying to extend that regex to cope with possible attributes
on the start tags (which would also need swapping intact). Then
consider an extreme case like this one

<tr id=extreme><td colspan="2">Let's miss out the optional closing tag
on this cell <td title="</tdis a 'closing' tag" class='extra'B
</td><td>C</td></tr>

You can do this sort of swap with a regex *if* you know in advance
that the data is amenable to it. If it's the sort of thing you might
need to do regularly, a tool that understands HTML is really the only
option. Read the document into a DOM (or similar structure) and
manipulate it there.

--
Chris
Aug 28 '06 #6
AES wrote:
In article <Gd**************@pigsonthewing.org.uk>,
Andy Mabbett <us**********@pigsonthewing.org.ukwrote:
I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.

Is there a tool which will allow me to do this?

Excel? (or other low cost spreadsheet)
Google Spreadsheet? =)

Aug 28 '06 #7

Andy Mabbett wrote:
I want to swap the order of columns four and five, without breaking
(indeed, without otherwise altering) the valid markup.
Time to learn regexes.

Then probably find yourself an editor that allows reasonable regex
processing, and to allow this processing to be applied only to a
highlighted selection. You could do it over the whole file with sed,
but that's often ghastly if you're just re-arranging one chunk of a
large file.

Sadly most editors that "support regexes" have bizarre, inconsistent
and partial ideas about regex syntax. Be careful here, especially with
TextPad -- try jEdit.

Aug 29 '06 #8
On 29 Aug 2006 03:00:46 -0700, "Andy Dingley" <di*****@codesmiths.com>
wrote:
>Then probably find yourself an editor that allows reasonable regex
processing, and to allow this processing to be applied only to a
highlighted selection. You could do it over the whole file with sed,
but that's often ghastly if you're just re-arranging one chunk of a
large file.
Or take the chunk that has to be changed to another file by itself,
change it and paste it back, if doing the whole file is easier.
Aug 29 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Doug Baroter | last post by:
What is a good method/mechanism to swap the position of multiple columns? For instance, tblXZY has the followings columns and respective positions: tblXZY ====== xyzUUID 1 fn 2 ln 3...
71
by: tomy_baseo | last post by:
I'm new to HTML and want to learn the basics by learning to code by hand (with the assistance of an HTML editor to eliminate repetitive tasks). Can anyone recommend a good, basic HTML editor that's...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
1
by: bidllc | last post by:
I'm working on a minor bug from an open source bug tracking system (bugtracket.net). It's a great app, but I don't want to bother the creator any more than I have to, so I thought I'd pose the...
1
by: Mat | last post by:
Please do i swap dbgrid columns in runtime from code? i want to do the samething like when user move columns Thanks you
0
by: Kevin Bartz | last post by:
-----Original Message----- From: Kevin Bartz Sent: Monday, August 09, 2004 10:37 AM To: 'mike@thegodshalls.com' Subject: RE: Out of swap space & memory Thanks for your reply, Mike!...
27
by: prt7u | last post by:
Howdy, I've started back afte a very long time of working with web pages for an organization that I am affiliated with (personally not professionally). Seeing that technology has advanced a lot...
0
by: langwadt | last post by:
On 27 Jun., 18:40, "David T. Ashley" <d...@e3ft.comwrote: Ultraedit has a great collum mode (alt-c to toggle between collum and normal mode) it can do what I think you want. it hard to...
5
by: dmf1207 | last post by:
Hi All! I'm new to javascript and need a little help with a simple puzzle im trying to design. I have a 600x100 pixel picture that I have sliced into 6 100x100 rectangles making a table of of 6...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.