?
Solved

Display XML in HTML tags

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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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).
Suggested Courses

777 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