0

I am currently trying out this example from jQuery website:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.parseXML demo</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p id="someElement"></p>
<p id="anotherElement"></p>
<script>
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "title" );
// Append "RSS Title" to #someElement
$( "#someElement" ).append( $title.text() );
// Change the title to "XML Title"
$title.text( "XML Title" );
// Append "XML Title" to #anotherElement
$( "#anotherElement" ).append( $title.text() );
</script>
</body>
</html>

I have a .XML file stored in the same directory, Desktop/example, as the HTML file as above, how do I link it? I tried chaning this line to:

var xml = "myXmlFile.xml",

it did not work

PhoonOne
  • 2,678
  • 12
  • 48
  • 76
  • You can read local text file using html5 `FileReader`, but only if it was selected by user input. See this question for more details: [how to read text file in javascript](http://stackoverflow.com/questions/13709482/how-to-read-text-file-in-javascript) – Shad Jan 14 '14 at 21:51
  • Thank you, how about a rest service URL? @Shad – PhoonOne Jan 14 '14 at 22:01
  • Sure, you can parse xml from response. `$.get('URL', function(data) { xmlDoc = $.parseXML(data); });` – Shad Jan 14 '14 at 22:15

0 Answers0