0

I was reading a tutorial on using XML data islands in HTML. I followed the tutorial and got my HTML table working with XML. But when I insert a second column into my table it no longer displays correctly. I tried modeling my table after the examples on w3schools but all my data is being displayed inline as opposed to on different lines, as you can see below: enter image description here

How do I make it so every persons data is displayed on its own row vertically?

HTML CODE:

<html>
    <body>
        <xml ID="xml-table">
            <root>
                <person>
                    <name>Tony</name>
                    <age> 25 </age>
                </person>

                <person>
                    <name>TJ</name>
                    <age>20</name>
                </person>

                <person>
                    <name>Lisa</name>
                    <age>28</age>
                </person>
            </root>
        </xml>

        <TABLE BORDER=1 DATASRC="#xml-table">
            <TR>
                <TD><SPAN DATAFLD="name"></SPAN></TD>
                <TD><SPAN DATAFLD="age"></SPAN></TD>
            </TR>
        </TABLE>
    </body>
</html>
chopper draw lion4
  • 12,401
  • 13
  • 53
  • 100
  • Question was already answered, see: http://stackoverflow.com/questions/17952660/html-data-binding-not-working-in-html – KIKO Software Aug 29 '14 at 19:54
  • That question was never answered. People on that thread said it was impossible to do it using this method but they never posted the correct solution. – chopper draw lion4 Aug 29 '14 at 20:02
  • Your right, let's wait for the correct solution to an impossible question. :-) Sorry, just kidding. The real solution should be made with Javascript and an example was given. See: http://stackoverflow.com/questions/649614/xml-parsing-of-a-variable-string-in-javascript/8412989#8412989 – KIKO Software Aug 29 '14 at 20:31

1 Answers1

0

The basic problem is that the XML is not valid. The second XML {person} node has an {age} node terminated by {/name}, which is obviously invalid. It should be terminated with {/age}.

Only the text data content of the nodes is rendered up to the bad node terminator. Hence all in line.

Once the node is fixed the "table" can read the XML and it renders in a table grid (at least in IE9).

I think a good trick is to test the XML segment by pasting it into a test.xml file and open it. It would be opened by the default web browser which is IE 9 on my Vista system and appear a color coded xml tree. If it does not then the XML is invalid.

  • In my explanation above the node names seem to have been replaced with blanks.?? The bad node is the second person node. it has an age node terminated with name node terminator. – TheProgster Feb 11 '15 at 08:47