Jump to content

display XML element(s) in HTML


teakupudoru

Recommended Posts

hi.i'm really hoping somebody will be able to help me out on this one...my problem is really straightforward and any help from a knowledgable xml/html guru would be greatly apprecited.i would like to display a specific xml element within the body of an html page. i am no expert, but i have looked thru all the tutorails on w3schools and i have managed to create my xml and xsl files using the cd catalogue example: http://www.w3schools.com/xsl/xsl_for_each.asp.the above example makes use of an xml database and produces a neat looking (xhtml) page using an xsl stylesheet. i have applied this example to my data and managed to produce my own database which displays thru an xsl stylesheet.however, i wish to display a specific element within an existing html page. specifically, how can i call up an element from the xml database and display it within an html page that already contains numerous lines of code (images, links, text, some flash etc.). obviously, i wish to avoid data isalnds and am unable to do it with xsl. which code should i use and is xsl necessary?thank you very much for your help.

Link to comment
Share on other sites

This question is answered in the XSLT FAQ. Now that you mentined it, I might make an XML one. Not now though... when I have just a bit more time. Anyway, see question 3.

Link to comment
Share on other sites

thanx for your replies! they were both very helpful. i have managed to use boenrobot's suggestion and show an xslt transformation inside the html.@ jesh: however, i think the httprequest method from http://w3schools.invisionzone.com/index.php?showtopic=9461 would be more effective and elegant in my case. unfortunately, i have not managed to apply it successfully, however. i am not quite sure where to place the code:

var xml = xmlhttp.responseXML;var books = xml.getElementsByTagName("book");var div1 = document.getElementById("div1");var div2 = document.getElementById("div2");div1.innerHTML = books[0].getElementsByTagName("title")[0].childNodes[0].data;div2.innerHTML = books[1].getElementsByTagName("title")[0].childNodes[0].data;

if you could possibly post this code here within context of the html file that would be most useful... sorry2b such a noob. :)

Link to comment
Share on other sites

All the code to build an xmlhttp object is in the AJAX tutorial:http://www.w3schools.com/ajax/default.aspIf you feel you need to skip ahead, it's on this page:http://www.w3schools.com/ajax/ajax_xmlhttprequest.aspI'd recommend going through the entire tutorial though, it's short enough. :)

Link to comment
Share on other sites

  • 5 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...