Solved

Display XML in HTML tags

Posted on 2011-02-28
6
225 Views
Last Modified: 2013-11-26
I want to display XML contents in my HTML document.  That is, the HTML contains xml and other html contents, NOT just an xml document.

For example, I want to display my form, tables, XML, ...

<html>
<form>
...
</form>
<xml>
...
</xml>
<table>
...
</table>
</html>

Open in new window


Where xml is the HTML tag to display the XML contents.

Basically, I want the xml  tag to be a combination of
<pre><code> to show the xml contents.

Also, I want this contents of the page to look like an xml document.  I do not just want to use a textarea tag to put the xml contents.  

I use php on the server if there are any available functions or should it be done with javascript?
0
Comment
Question by:pmsguy
  • 3
6 Comments
 
LVL 7

Expert Comment

by:dxdinh
ID: 34999587
you probably have to apply xslt to format the xml
some tutorial to get your feet wet from google  - you will be up and running in no time

http://www.w3schools.com/xsl/xsl_transformation.asp
 
 
0
 

Author Comment

by:pmsguy
ID: 34999765
How would I easily apply the xslt.

For example, I have xml contents:


<?xml version="1.0"?>
<NotificationHeader>
<PartnerName>UserName</PartnerName>
<PartnerPassword>Password</PartnerPassword>
</NotificationHeader>
<Message>This is an MT message.</Message>
<Profile>1234</Profile>

Open in new window

0
 
LVL 7

Accepted Solution

by:
dxdinh earned 500 total points
ID: 35013652
btw, your xml not well-formed so I made a slightly modification

so save the xml as test.xml
and xls as test.xsl

link the XSL style sheet reference to your XML document

<?xml-stylesheet type="text/xsl" href="test.xsl"?>


view your xml within modern browser you will see the result

when apply to your server you will need to insert the link to your xml to point to your xsl file resides on your server

 Hope that helps !
 
--- start test.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<NotificationHeader>
<PartnerName>UserName</PartnerName>
<PartnerPassword>Password</PartnerPassword>
<Message>This is an MT message.</Message>
<Profile>1234</Profile>
</NotificationHeader>

--- end of test.xml

--- start test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My Title</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Partner Name</th>
      <th>Partner Password</th>
    </tr>
    <xsl:for-each select="NotificationHeader">
    <tr>
      <td><xsl:value-of select="PartnerName"/></td>
      <td><xsl:value-of select="PartnerPassword"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

-- end test.xsl

Open in new window

0
 
LVL 7

Expert Comment

by:dxdinh
ID: 35013658
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question