0

Helo, I'm a beginner in javascript,

For a project, I need to parse an XML File with JS, I'm using Jquery.

How can I open xml by its url please?

var xml = "Fichier.xml",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),

I have an error at this line xmlDoc = $.parseXML( xml ), : Invalid XML : test.xml (error 0)

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531

1 Answers1

0

$.parseXML() expects a valid xml content as its argument, in your case you have a url which is not a valid xml thus your are getting the error.

What you can do is to use a ajax request to load the remote content and in its success callback you can do your processing

var xml = "Fichier.xml";
$.get(xml, function (doc) {
    var $xml = $(doc);
    //do stuff with $xml
}, 'xml');
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531