?
Solved

Display XML in HTML tags

Posted on 2011-02-28
6
Medium Priority
?
231 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
4 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

839 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