Solved

Display XML in HTML tags

Posted on 2011-02-28
6
222 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
HTML page and JavaScript 2 49
How do I access property of nested object in PHP? 3 21
CSS grid style change 2 13
sql sentence 2 8
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now