Read file packaged with Chrome extension in content script
-
I am developing a Chrome extension that needs to package an XML file (a trie data structure) and be able to read that file from the content script. So the content script will instantiate the trie after reading the data from the XML file every time the extension is loaded. How to read this XML file through content script (or background page)? Do I need to use localStorage?
-
Answer:
A simple ajax request to the XML file should give you the XML DOM nodes: function request(url) { var xhr = new XMLHttpRequest(); try { xhr.onreadystatechange = function(){ if (xhr.readyState != 4) return; if (xhr.responseXML) { console.debug(xhr.responseXML); } } xhr.onerror = function(error) { console.debug(error); } xhr.open("GET", url, true); xhr.send(null); } catch(e) { console.error(e); } } function init() { request("sample.xml"); } You would need to use a js-based xml parser or write your own. It might be easier to save your data as a JSON object.
Vikesh at Stack Overflow Visit the source
Related Q & A:
- How to Show or Read docx file?Best solution by Stack Overflow
- how to open a link in new tab in chrome extension?Best solution by Stack Overflow
- How to read file from specific word in php?Best solution by Stack Overflow
- Is it possible to send message to Chrome Extension from Java Desktop Application?Best solution by Stack Overflow
- How will my Google Chrome/Firefox be able to read Korean?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.