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.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.