1

I am building a Winform web browser. I have a history.xml file which stores history of the browser. I need to display that in the browser window so the user can click the hyperlink of the website and navigate. I want to use JavaScript to parse the XML file and display the content in table form. How do I parse XML using JS? I am not sure about what to use in this situation. I already have a good HTML page with CSS to display history. Please advice.

My XML file looks like this.

<?xml version="1.0" encoding="utf-8"?>
<browsing>
  <history date="08/10/2012">
    <url>http://www.google.ca/</url>
    <time>12:52 AM</time>
  </history>
  <history date="08/10/2012">
    <url>http://www.facebook.com/</url>
    <time>12:53 AM</time>
  </history>
  <history date="08/10/2012">
    <url>http://ca.msn.com/</url>
    <time>9:51 PM</time>
  </history>
</browsing>
1
  • 1
    Why not use XSLT to style it and show it as it is? Commented Oct 10, 2012 at 16:31

1 Answer 1

1

Use jQuery's $.get().

$.get("history.xml", function(xml) {
  $(xml).find("history:nth(0)").find("url").val(); // returns http://www.google.ca/
  $(xml).find("history:nth(1)").getAttribute("date"); // returns 08/10/2012
}, "xml");

EDIT: While i was writing this answer, your post was edited. To display it in a table form, it might be easier just to use XSLT. It's specifically designed for styling 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.