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!!

4
  • If the problem only consists of presenting the xml on the page this should help you on the way: stackoverflow.com/questions/5744064/… Commented Dec 30, 2012 at 17:32
  • By locally do you mean the client computer? Commented Dec 30, 2012 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. Commented Dec 30, 2012 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 Commented Dec 30, 2012 at 18:40

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I will see that :) Thanks!
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>

Comments

0

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

1 Comment

I want just the other way, I want to read an xml in html5 to display the data in the xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.