0

I have been searching how to display data from a xml file in a html5 application. I have a html5 web page that has to read data from a xml saved locally in a folder. I have been trying with xslt, java and everything but I really can't.

Can someone help me please? Any user guide for dummies? Any tip? Thanks!!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Manuelpalcaraz
  • 69
  • 3
  • 10
  • If the problem only consists of presenting the xml on the page this should help you on the way: http://stackoverflow.com/questions/5744064/html5-file-api-reading-in-an-xml-text-file-and-displaying-it-on-the-page – Tobias Nilsson Dec 30 '12 at 17:32
  • By locally do you mean the client computer? – Oded Dec 30 '12 at 17:33
  • Yes, I want to display the data to the user. The data comes from a database that I have passed to a xml and I want to display this data. – Manuelpalcaraz Dec 30 '12 at 18:35
  • I do not want just display all the text of the xml, I want to read the xml and put some data in the html5 code – Manuelpalcaraz Dec 30 '12 at 18:40

3 Answers3

2

I always retrieve my XML using AJAX, so for me:

theXML = xmlhttp.responseXML.documentElement;
// documentElement is the root of the XML

var elementXXX = theXML.getElementsByTagName('elementXXX')[0].childNodes[0].nodeValue;
//This will retrieve a first level element in the XML

If there are multiple nodes, then you have to loop through them and extract the nodeValue in each iteration. I find it helpful to think about the content you want to extract from an XML element as the first Child of the element--

Hope this helps.

John Palmer
  • 25,356
  • 3
  • 48
  • 67
1

I know this question is old but I will add to it anyway for others seen as I am currently doing something similar.

There are many ways to pull in XML data to be shown on a web page. To do it using JQuery, for example with an XML file called data.xml:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "data.xml",
        dataType: "xml",
        success: xmlParser
    });
});

function xmlParser(xml) {
   // The data to be read in..
}
</script>
fionaredmond
  • 639
  • 7
  • 15
0

Using jQuery, here is a guide: http://api.jquery.com/jQuery.parseXML/