Welcome to WebmasterWorld Guest from 54.163.49.19

Forum Moderators: httpwebwitch

Message Too Old, No Replies

importing simple xml strings into html

     
8:22 am on Mar 31, 2011 (gmt 0)

New User

joined:Mar 31, 2011
posts: 1
votes: 0


Hi, I have a very simple xml file like this:


<MyText>
<Text1>first text going to website
</Text1>
<Text2>second text going to website
</Text2>
</MyText>


I need my html(index) file to pick up the text from the xml file. What is the simplest solution how to do this? Could anyone please give me help in how to code this?

The nearest I am a solution, is doing as follows - making a xsl file looking something like this:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>
<xsl:value-of select="MyText/Text1" /><br/>
</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


and linking to it in the xml file via this line

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


But I don't know how to put this in the right place of my html file.

Or are there other ways to do this?
I appreciate all the help I can get!
5:56 pm on May 11, 2011 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


your best bet is to use a server-side programming language like PHP, C#, Java, Perl, Ruby, or whatever you're comfortable with... use it to grab the XML file, parse it to get the text, and output that into your HTML layout.

XSL transformation is typically performed on an entire document; it's not possible (AFAIK) to drop a little piece of it into HTML.

It's possible to do it with JavaScript, but I don't recommend it.