in reply to Re^3: Going between XML and Cgi by way of DTD
in thread Going between XML and CGi by way of DTD

There are two intertwined challenges here: (1) Generating an display/editing form that corresponds precisely to the XML and the DTD. (2) Rendering this in a way that it makes sense visually to the user.

I think I can do that for your example:

<html><body> <table border=1 cellspacing=0 cellpadding=3> <caption>Items</caption> <tr><td rowspan=6>Item1</td><td colspan=2>foo:</td><td>a</td></tr> <tr><td colspan=2>bar:</td><td>b</td></tr> <tr><td colspan=2>baz:</td><td>c</td></tr> <tr><td rowspan=3>Item2</td><td>foo:</td><td>d</td></tr> <tr><td>bar:</td><td>e</td></tr> <tr><td>baz:</td><td>f</td></tr> <tr><td rowspan=3>Item3</td> <td colspan=2>foo: </td><td>x</td></tr> <tr><td colspan=2>bar:</td><td>y</td></tr> <tr><td colspan=2>baz:</td><td>z</td></tr> </body></html>
(If you download this into a scratch.html file, and view the result in your browser, you'll see better what I'm doing here.)

Some tricks here - you've got to traverse the whole tree before you start generating the table – you've got to know what the maximum depth is. You make the table that many columns wide. And you have to know how many leaf elements there are within each item, so you know how many rows tall to make its block.

I've previously generated HTML tables to represent structures nested 10 levels deep, with on the order of 200 elements.

The nesting is a bit of a problem, but one I've solved previously.

Replies are listed 'Best First'.
Re^5: Going between XML and Cgi by way of DTD
by Cody Pendant (Prior) on Aug 27, 2007 at 04:12 UTC
    I take your point, but you're creating HTML based on my data -- I never said that wasn't possible! How would you create an HTML form based on the DTD?


    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
      Let we are in situation, when xml document (or its stub) is on the server and user wants to edit it. Consequently, the application can use both (current) document and (static) DTD for creating web form - in other words, the web form have to be created dynamicaly, according to current data and some validation schema.