Free Newsletters
Technology & Business Daily

InfoWorld
Log-in | Register

  Friday, May 16, 2003 

Toggling between HTML and XML

The HTML Tidy procedure I spelled out here is proving awkward. If I screw something up that Tidy can't fix, I wind up checking the document in an XML parser. A convenient parser is the one in MSIE, and lately I've been using it for this purpose. This is awkward too, however. For a few days, I tried this procedure:

  • Write the file, e.g. file.html
  • Copy the file to, e.g., file.xml.
  • Check file.xml in MSIE.
  • Extract and post contents.

But the edit/copy/check cycle is ridiculous. Couldn't I toggle the same file between two modes? Here's one approach. By adding this to the file:

<head><meta http-equiv="content-type" content="text/xml"/></head>

I could view as XML and check well-formedness. Now toggling between HTML and XML modes was as simple as changing between "text/xml" and "text/html" and reloading. Here's are both views, for this in-progress document, in MSIE on Mac OS X:

Content-type: text/html

Content-type: text/xml

What I didn't discover until later is that, for reasons I'm sure someone will explain to me, this doesn't work in MSIE 6. Not knowing that, I next attempted what seemed like a brilliant hack. Why not make a couple of bookmarklets to poke the META HTTP-EQUIV tags into the DOM? Then it'd be just a one-click deal to toggle from HTML to XML and back.

Here's a snippet that (in theory) does the HTML-to-XML switcheroo:

<a href="javascript:void( function() {var element=document.createElement('meta'); element.setAttribute('http-equiv','content-type'); element.setAttribute('content', 'text/xml'); var oldhead = document.getElementsByTagName('head')[0]; var newhead=document.createElement('head'); newhead.appendChild(element); document.firstChild.replaceChild(newhead, oldhead);} () )">switchToXML</a>

Mozilla's amazingly cool DOM inspector enables us to verify that the expected change was made. Here's the document in its default text/html mode:

Content-type: text/html

And here's the document after clicking on that javascript: link to modify the META HTTP-EQUIV element:

Content-type: text/xml

It works! Except no, it doesn't. Although the DOM exactly matches the DOM obtained by reading in a file that originally contains an HTTP-EQUIV of text/xml, MSIE doesn't react to the dynamic change.

Sadly it's all kind of moot anyway. Safari won't parse XML, Mozilla parses without the XML viewer, but like MSIE 6 doesn't seem to want to let HTTP-EQUIV override the filename's extension. Ideas?

 

Tools for rules

The dust was thick on my copy of the 1985 Clocksin and Mellish classic, Programming Prolog. But Ted Neward, author of the forthcoming book Effective Enterprise Java, brought it all rushing back: expert systems, declarative rules engines, predicate calculus, backward- vs. forward-chaining evaluation.

Neward gives an example on his weblog why this obscure discipline is back in vogue.
"If the guy filing the expense report files a 334-B form, then the upper limit on the total is twice his Personal Expense Liability total (which you get from the HR database, of course), unless his boss is an Assistant Vice President, in which case we have to get departmental approval from two managers and the AVP himself." [The Mountain of Worthless Information]
Today we program this stuff in procedural languages, and we make a hell of a mess doing so. Wouldn't it be great if we could declare a bunch of rules and have a rules engine work out the consequences? As Ted points out, this is the moral equivalent of using SQL to say what you want done with data not how. [Full story at InfoWorld.com]

For those (like me) who haven't followed recent developments in the world of rules engines, here are some signposts:

 


Recent Entries


















































Sponsored Technology Links

 
 
 HOME  NEWS  BLOGS  PODCASTS  VIDEOS  TECHNOLOGIES  TEST CENTER  EVENTS  CAREERS   About | Advertise | Awards | RSS | Contact Us 

Copyright © 2008, Reprints, Permissions, Licensing, IDG Network, Privacy Policy, Terms of Service.
All Rights reserved. InfoWorld is a leading publisher of technology information and product reviews on topics including viruses,
phishing, worms, firewalls, security, servers, storage, networking, wireless, databases, and web services.

CIO :: ComputerWorld :: CSO :: Demo :: GamePro :: Games.net :: IDG Connect :: IDG World Expo
Industry Standard :: IT World :: JavaWorld :: LinuxWorld :: MacUser :: Macworld :: Network World :: PC World :: Playlist