Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display xml data as it is in a table.

Example:



HTML
<table><tbody><tr><td>Heading1</td> <td>Heading2</td> <td>Heading 3</td></tr><tr><td>value 1</td>  <td>value 2</td><td>
<arrayofmenu_bo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<menu_bo>
    <id>2
    <createdby>0
    <createdon>0001-01-01T00:00:00
    <modifiedby>0


</td></tr></tbody></table>


What I have tried:

when i try to display it is displaying in below format, but I need to show as it is in xml format (with nodes). How can I do this, please advise

Heading 1 Heading 2 Heading 3 

value 1  value 2    2   0    0001-01-01T00:00:00    0
Posted
Updated 21-Apr-20 4:29am
v2

To display XML text in a ML text file, you should use the CDATA tag:
CDATA - Wikipedia[^]
XML - CDATA Sections - Tutorialspoint[^]
HTML
<table><tbody><tr><td>Heading1</td> <td>Heading2</td> <td>Heading 3</td></tr><tr><td>value 1</td>  <td>value 2</td><td>
<![CDATA[<arrayofmenu_bo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<menu_bo>
    <id>2</id>
    <createdby>0</createdby>
    <createdon>0001-01-01T00:00:00</createdon>
    <modifiedby>0</modifiedby>
</menu_bo>
]]>
</td></tr></tbody></table>

Note that I added in bold closing tags which were missing from the XML text you provided.
 
Share this answer
 
Comments
Richard Deeming 21-Apr-20 10:22am    
That doesn't seem to work in an HTML document - the output appears as:
Heading1   Heading2   Heading 3
value 1    value 2    2 0 0001-01-01T00:00:00 0 ]]>
You'll need to HTML-encode the XML if you want it to appear "as-is" in your HTML document. In particular:
  • <&lt;
  • >&gt;
  • &&amp;

You'll also want to wrap it in a <pre> element to preserve the white-space.
HTML
<pre>
&lt;arrayofmenu_bo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
&lt;menu_bo&gt;
    &lt;id&gt;2&lt;/id&gt;
    &lt;createdby&gt;0&lt;/createdby&gt;
    &lt;createdon&gt;0001-01-01T00:00:00&lt;/createdon&gt;
    &lt;modifiedby&gt;0&lt;/modifiedby&gt;
&lt;/menu_bo&gt;
&lt;/arrayofmenu_bo&gt;
</pre>
Demo[^]
<pre>: The Preformatted Text element - HTML: Hypertext Markup Language | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900