-1

My folder hierarchy is as follows:

a/a.XML a/b/b.XML

i will select a.XML file and i have read this file. Now i have path of b.XML file. My question is how to read this XML file as i am not getting its input i only have its path. I have searcg on net but i didnt found any help how to read XML file wihout giving its input. I want my code to be run in google chrome

My code for reading XML file throug input is as follows:

   if(filePath.files && filePath.files[0]) 
        {           
        reader.onload = function (e) 
        {
            output = e.target.result;
            console.log("file path"); 
            console.log(output);
}
}
Muneem Habib
  • 1,046
  • 4
  • 18
  • 49

2 Answers2

0

The below links should explain you clearly how to read XML using JavaScript.

However, if you are trying to access multiple elements repeatedly, you may also try this...Convert your XML to JSON format (You will find many articles on the Internet on how to convert XML to JSON programatically). JSON can be very easily parsed using JavaScript.It reduces the number of DOM calls you make to reference a particular element and hence it is faster.

http://www.w3schools.com/XML/tryit.asp?filename=tryxml_parsertest

http://www.codetoad.com/xml_javascripti_tutorial.asp

http://www.w3schools.com/XML/xml_examples.asp

http://www.peachpit.com/articles/article.aspx?p=29307&seqNum=4

Check the above Link

Mr X
  • 31
  • 3
0

From your comment, it seems you're trying to read the xml file from you local system. Which is impossible to do. Following are the error you will suffer

In chrome it returns 404 error.

In FF it retuns 0 [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)".

So first host your file in some server and then load it.

Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
  • sir i have read xml file from local system and its working very nice. Now what i want is to push all files to FileList interface manually which are place in same folder on which user selects XML file – Muneem Habib Nov 27 '13 at 09:41