Solved

Display XML in HTML tags

Posted on 2011-02-28
6
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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