How can I read/write data from a file?
Posted
by
samy
on Stack Overflow
See other posts from Stack Overflow
or by samy
Published on 2012-10-06T15:12:09Z
Indexed on
2012/10/06
15:37 UTC
Read the original article
Hit count: 305
I'm writing a simple chrome extension. I need to create the ability to add sites URLs to a list, or read from the list.
I use the list to open the sites in the new tabs.
I'm looking for a way to have a data file I can write to, and read from. I was thinking on XML. I read there is a problem changing the content of files with Javascript.
Is XML the right choice for this kinda thing?
I should add that there is no web server, and the app will run locally, so maybe the problem websites are having are not same as this.
Before I wrote this question, I tried one thing, and started to feel insecure because it didn't work.
- I made a XML file called Site.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Sites>
<site>
<url>
http://www.sulamacademy.com/AddMsgForum.asp?FType=273171&SBLang=0&WSUAccess=0&LocSBID=20375
</url>
</site>
<site>
<url>
http://www.wow.co.il
</url>
</site>
<site>
<url>
http://www.Google.co.il
</url>
</site>
- I made this script to read the data from him, and put in on the html file.
function LoadXML() {
var ajaxObj = new XMLHttpRequest();
ajaxObj.open('GET', 'Sites.xml', false);
ajaxObj.send();
var myXML = ajaxObj.responseXML;
document.write('<table border="2">');
var prs = myXML.getElementsByTagName("site");
for (i = 0; i < prs.length; i++) {
document.write("<tr><td>");
document.write(prs[i].getElementsByName("url")[0].childNode[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table");
}
© Stack Overflow or respective owner