-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);
}
}
3
  • What would be the input you are talking about? Commented Nov 27, 2013 at 6:43
  • i mean throug dialog i choose XML file and it is reading fine Now i have another xml file in same hierarchy i want to read it Commented Nov 27, 2013 at 6:45
  • If you know file path and file name, then make ajax request from javascript. This will give xml string in success callback. Later, you can parse them. Commented Nov 27, 2013 at 8:56

2 Answers 2

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

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

2 Comments

sir issue is not XML parsing i have parsed XML. Issue is how to read that XML file without any dialog
these tutorials are sending https request. i have to read xml file in locla machine
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.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.