JavaScript - String Parsing Problem
I'm developing a DHTML based Flashcard app that will work using firefox (MiniMo on Mobile Devices). It's working fine (reads and writes datafile to and from the local disk). However, when i start reviewing the flashcards, it seems to have some parsing issues.
Do explain more about the data file, it is a 3 record CSV file with 3 catagories: ChineseCharacter, PinYin, English For some reason or another, i can figure out how to correctly pars out and put the correct data in the corresponding Data Arrays. I would like to get this program working as soon as i can, i plan to use it to study for the HSK test (Chinese proficiency test). I'm supposed to take it in about 4 months. - yes im cramming here's my code: Code: <html> <head> <script language="javascript"> // Set Global Variables var ChineseCard = new Array(); var PinYinCard = new Array(); var EnglishCard = new Array(); var Records = new Array(); var Know = 0; var DontKnow = 0; var CurrentCard = 0; var NumberOfCards = 0; var DataFile = "C:" + String.fromCharCode(92) + "FlashCard.txt"; var Delimeter = ","; function init() { document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; document.getElementById("MainMenu").style.visibility = "visible"; } function ShowPlayer() { document.getElementById("FlashCardPlayer").style.visibility = "visible"; document.getElementById("MainMenu").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; LoadFlashCard(); } function ShowEditor() { document.getElementById("FlashCardEditor").style.visibility = "visible"; document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("MainMenu").style.visibility = "hidden"; } function ShowMain() { document.getElementById("MainMenu").style.visibility = "visible"; document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; } function ClickShowPinYin() { document.getElementById("PinYin").value = PinYinCard[CurrentCard]; } function ClickShowEnglish() { document.getElementById("English").value = EnglishCard[CurrentCard]; } function ClickKnow() { Know = Know + 1; if(CurrentCard == NumberOfCards) { // Display the score alert("You scored " + Know + " out of " + NumberOfCards); CurrentCard = 0; Know = 0; DontKnow = 0; // clear all textboxes and put index(0) chinese character into the chinese character textbox } CurrentCard = CurrentCard + 1; document.getElementById("PinYin").value = ""; document.getElementById("English").value = ""; document.getElementById("ChineseCharacter").value = ChineseCard[CurrentCard]; } function ClickDontKnow() { DontKnow = DontKnow + 1 if(CurrentCard == NumberOfCards) { // Display the score alert("You scored " + Know + " out of " + NumberOfCards); CurrentCard = 0; Know = 0; DontKnow = 0; // clear all textboxes and put index(0) chinese character into the chinese character textbox } CurrentCard = CurrentCard + 1; document.getElementById("PinYin").value = ""; document.getElementById("English").value = ""; document.getElementById("ChineseCharacter").value = ChineseCard[CurrentCard]; } function ClearEditor() { // Clear all the text boxes in the editor document.getElementById("EditChinese").value = ""; document.getElementById("EditPinYin").value = ""; document.getElementById("EditEnglish").value = ""; } function WriteData() { // Conicate the Record data var WriteData = document.getElementById("EditChinese").value + Delimeter + document.getElementById("EditPinYin").value + Delimeter + document.getElementById("EditEnglish").value + "\r"; // Load the data file's current contents var OldData = LoadFromDisk(DataFile); if (OldData == null) { var WriteDataUTF8 = utf8Encode(WriteData); // The file was blank, so don't try to append null content data SaveToDisk(DataFile, WriteDataUTF8 + "\n"); } else { var OldDataUTF8 = utf8Decode(OldData); var AppendData = OldDataUTF8 + WriteData + "\n"; var UTF8data = utf8Encode(AppendData) // Write the data to the file SaveToDisk(DataFile, UTF8data); } // Clear the TextBoxes to prepare for the next entry ClearEditor(); } function LoadFlashCard() { // Load the FlashCard Information from the DataFile into the Arrays var LoadData = LoadFromDisk(DataFile); // Convert the Datafile from UTF8 to ASCII var LoadDataUTF8 = utf8Decode(LoadData); Records = LoadDataUTF8.split(Delimeter); // Load the Elements in to the ChineseText, PinYin, and English Arrays NumberOfCards = (Records.length -1) / 2; NumberOfRecords = NumberOfCards * 3; // Load the Chinese Characters var Ptr = 0; for (var x = 0; x < NumberOfRecords; x = x + 3) { ChineseCard[Ptr] = Records[x]; Ptr++; } Ptr = 0; // Load the PinYin for (var x = 1; x < NumberOfRecords; x = x + 3) { PinYinCard[Ptr] = Records[x]; Ptr++; } Ptr = 0; // Load the English for (var x = 2; x < NumberOfRecords; x = x + 3) { EnglishCard[Ptr] = Records[x]; Ptr++; } alert(ChineseCard[1]); alert(PinYinCard[1]); alert(EnglishCard[1]); } function SaveToDisk(FileName, Content) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission to save file was denied."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( FileName ); if ( file.exists() == false ) { file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var output = Content; var result = outputStream.write( output, output.length ); outputStream.close(); } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } // ***************** The following are the functions for UTF8 *************************** // if these are removed or modified in any way, the foreign language characters might not display correctly or at all // Use utf8Encode(str) to Encode data to UTF8 format // Use utf8Decode(utf8Str) to Decode data to ASCII format //an alias of String.fromCharCode function chr(code) { return String.fromCharCode(code); } //returns utf8 encoded charachter of a unicode value. //code must be a number indicating the Unicode value. //returned value is a string between 1 and 4 charachters. function code2utf(code) { if (code < 128) return chr(code); if (code < 2048) return chr(192+(code>>6)) + chr(128+(code&63)); if (code < 65536) return chr(224+(code>>12)) + chr(128+((code>>6)&63)) + chr(128+(code&63)); if (code < 2097152) return chr(240+(code>>18)) + chr(128+((code>>12)&63)) + chr(128+((code>>6)&63)) + chr(128+(code&63)); } //it is a private function for internal use in utf8Encode function function _utf8Encode(str) { var utf8str = new Array(); for (var i=0; i<str.length; i++) { utf8str[i] = code2utf(str.charCodeAt(i)); } return utf8str.join(''); } //Encodes a unicode string to UTF8 format. function utf8Encode(str) { var utf8str = new Array(); var pos,j = 0; var tmpStr = ''; while ((pos = str.search(/[^\x00-\x7F]/)) != -1) { tmpStr = str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0]; utf8str[j++] = str.substr(0, pos); utf8str[j++] = _utf8Encode(tmpStr); str = str.substr(pos + tmpStr.length); } utf8str[j++] = str; return utf8str.join(''); } //it is a private function for internal use in utf8Decode function function _utf8Decode(utf8str) { var str = new Array(); var code,code2,code3,code4,j = 0; for (var i=0; i<utf8str.length; ) { code = utf8str.charCodeAt(i++); if (code > 127) code2 = utf8str.charCodeAt(i++); if (code > 223) code3 = utf8str.charCodeAt(i++); if (code > 239) code4 = utf8str.charCodeAt(i++); if (code < 128) str[j++]= chr(code); else if (code < 224) str[j++] = chr(((code-192)<<6) + (code2-128)); else if (code < 240) str[j++] = chr(((code-224)<<12) + ((code2-128)<<6) + (code3-128)); else str[j++] = chr(((code-240)<<18) + ((code2-128)<<12) + ((code3-128)<<6) + (code4-128)); } return str.join(''); } //Decodes a UTF8 formated string function utf8Decode(utf8str) { var str = new Array(); var pos = 0; var tmpStr = ''; var j=0; while ((pos = utf8str.search(/[^\x00-\x7F]/)) != -1) { tmpStr = utf8str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0]; str[j++]= utf8str.substr(0, pos) + _utf8Decode(tmpStr); utf8str = utf8str.substr(pos + tmpStr.length); } str[j++] = utf8str; return str.join(''); } </script> </head> <body onload="init()"> <!-- ***************************************** Flash Card Player ***************************************** --> <div id="FlashCardPlayer" style="position: absolute; left: 0px; top: 0px;" > <input id="ChineseCharacter" type="textbox" style="position: absolute; left: 75px; top: 5px; width: 100px; height: 100px; font-size: 35px;"> <input id="PinYin" type="textbox" style="position: absolute; left: 5px; top: 110px; width: 225px;" > <input id="English" type="textbox" style="position: absolute; left: 5px; top: 135px; width: 225px;"> <input type="button" value="Know" style="position: absolute; left: 5px; top: 170px; width: 100px; height: 30px;" onclick="ClickKnow();"> <input type="button" value="Dont Know" style="position: absolute; left: 125px; top: 170px; width: 100px; height: 30px;" onclick="ClickDontKnow();"> <input type="button" value="PinYin" style="position: absolute; left: 5px; top: 210px; width: 100px; height: 30px;" onclick="ClickShowPinYin();"> <input type="button" value="English" style="position: absolute; left: 125px; top: 210px; width: 100px; height: 30px;" onclick="ClickShowEnglish();"> <a href="" style="position: absolute; left:10px; top: 245px;" onclick="ShowMain();">Home</a> </div> <!-- ****************************************** Flashcard Editor ****************************************** --> <div id="FlashCardEditor" style="position: absolute; left: 0px; top: 0px;"> <input id="EditChinese" style="position: absolute; left: 75px; top: 5px; width: 100px; height: 100px; font-size: 35px;" type="textbox"> <input id="EditPinYin" style="position:absolute; left: 5px; top: 110px; width: 225px;" type="textbox"> <input id="EditEnglish" style="position:absolute; left: 5px; top: 135px; width: 225px;" type="textbox"> <input id="EditClearTextButton" value="Clear" style="position:absolute; left: 5px; top: 180px; width: 100px; height: 30px;" onclick="ClearEditor();" type="button"> <input name="EditOKButton" value="OK" style="position: absolute; left: 125px; top: 180px; width: 100px; height: 30px;" onclick="WriteData();" type="button"> <a href="" style="position: absolute; left:10px; top: 225px;" onclick="javascript:Alert("*sigh* i'm getting to it!");">New</a> <a href="" style="position: absolute; left:10px; top: 245px;" onclick="ShowMain();">Home</a> <br> </div> <!-- ****************************************** Define the Layer for the Main menu ****************************************** --> <div id="MainMenu" style="position: absolute; left: 0px; top: 0px;"> These are the instructions for the Flashcard App. In the future, there should be a score board and a selection of word lists and other such things. However, it's blank for now until i finish this app :) <input value="Study Flashcards" style="position: absolute; left: 50px; top: 170px; width: 120px; height: 30px;" onclick="javascript:ShowPlayer();" type="button"> <input value="Edit Flashcards" style="position: absolute; left: 50px; top: 210px; width: 120px; height: 30px;" onclick="ShowEditor();" type="button"> </div> </body> </html> Similar TutorialsI wanted to parse (split) a string between numbers, operators and words. I can get 2 out of 3 of my desires using this... Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Token Parser </title> </head> <body> <pre id="debug"></pre> <script type="text/javascript"> function splitInfix(str) { var tarr = str.match(/[\d*|\S*]/g); return tarr.join(' '); } var str = '', tokens = ''; str = '1+2+3'; tokens = splitInfix(str); document.getElementById('debug').innerHTML = str + '<br>' + tokens + '<br>Spaces correctly<p>'; // OK str = '1+2^3*(4-3)'; tokens = splitInfix(str); document.getElementById('debug').innerHTML += str + '<br>' + tokens + '<br>Spaces correctly<p>'; // OK str = tokens; tokens = splitInfix(str); document.getElementById('debug').innerHTML += str + '<br>' + tokens + '<br>Spaces correctly<p>'; // OK str = '1+2^3*sin(4-3)'; tokens = splitInfix(str); document.getElementById('debug').innerHTML += str + '<br>' + tokens + '<br>Spaces sin wrong<p>'; // NFG str = 'cos(180)+sin(90)'; tokens = splitInfix(str); document.getElementById('debug').innerHTML += str + '<br>' + tokens + '<br>Spaces cos & sin wrong<p>'; // NFG </script> </body> </html> The OK examples appear to accomplish what I want, but the Not Fully Good (NFG) examples put spaces between the words as well, which I don't want. Is there something I can add to the function to make the output appear as words cos & sin instead of c o s & s i n ? Or is there another function I can use to combine only the characters [a-z] and [A-Z] into whole words while leaving the spaces as is for the other characters and numbers? Thanks for any thoughts on the matter. Hello All, I have a string array in a class file that contains 5 values, which I need to display on the jsp page. but when I send it to the javascript it prints [Ljava.lang.String;@104f8b8 . what do i do about it. I am a new to javascript. Is there a way to get my array data from the response object. Please help. Hey, Im fairly new to javascript but I am an experianced php programmer. I have been parsing XML information using php, but my CPU usage has been too high recently due to this. I am trying to convert my scripts to javascript, but I am unsure how I can do this using javascript. I think that if I get started off, the rest will be easy. One of my XML files is located at Code: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=bbcradio1&api_key=c910b0bc1e2d4e64964ebcd2d69c255c&limit=500 Basically I have been trying to grab the Name, Artist and large image of the most recent <track>. Any help would be greatly appreciated and linked too on my website . Tim Hey guys. I'm trying to display a grid of data basically, but inside a table and with appropriate closing and beginning of td and tr tags. I'm having a very weird problem. Here is my code: Code: tasks = document.getElementById('tasks'); var i = 0; tasks.innerHTML = <tablebgcolor=silver>"; while (i < 3) { tasks.innerHTML = tasks.innerHTML + "<tr><td>"; tasks.innerHTML = tasks.innerHTML + text[i][0]; tasks.innerHTML = tasks.innerHTML + "</td><td>"; tasks.innerHTML = tasks.innerHTML + text[i][1]; tasks.innerHTML = tasks.innerHTML + "</td><td>"; tasks.innerHTML = tasks.innerHTML + text[i][2]; tasks.innerHTML = tasks.innerHTML + "</td></tr>"; i++; } tasks.innerHTML = tasks.innerHTML + "</table>"; The html just doesn't work when it's in a string. I have to put each "<tr><td>", "</td><td>", </td></tr>", <table bgcolor=silver>", etc. into it's own variable and do it that way. That doesn't seem like it should be happening and I don't think it would be good to do it that way in the long run. Can someone tell me what I'm doing wrong? The closest thread I found related to this was http://www.codingforums.com/showthread.php?t=199192 I suppose I don't really know how database connections work. I can use Jet to connect to a .mdb on my C drive: "C:\\northwind.mdb" But not on the server: "\\something.anotherthing.mil\\Code34\\_fs34Projects\\ANTS\\FBG\\Database\\dev\\db\\northwind.md b"; (tried single and double slashes) Any ideas? here's the code: Code: $(document).ready(function() { warg = new unpackArgs(); //warg.dbPath = "\\something.anotherthing.mil\Code34\_fs34Projects\ANTS\FBG\Database\dev\db\database.mdb"; warg.dbPath = "\\\\something.anotherthing.mil\\Code34\\_fs34Projects\\ANTS\\FBG\\Database\\dev\\db\\database.mdb"; warg.rootID = warg.ROOTID_HIGHEST; warg.entryType = warg.ENTRYTYPE_NONE; warg.entryOption = warg.ENTRYOPTION_SHOWBUTTONS; warg.tableName = "Foods"; warg.fieldList = "*"; var cn = new ActiveXObject("ADODB.Connection"); cn.Mode = MODE_ADMODEREAD; var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "+warg.dbPath; try { cn.Open(strConn,null,null,-1); ...etc... Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> Anyone that can help on this one it would be greatly appreciated... I need to make a form parses a result from column 1 of txt/csv file that has 7 columns. Column 1 is pay, column 2-7 are how many and the associated rows are the answers. In short 1 2 3 4 5 6 700 50 55 62 75 80 99 so if the customer enters i make 700 and i need 2 the result would be 55 as the output. Any idea on how to make that work with javascript? if (pay <=700 && widgets = 2) { document.write(55) elseif (pay <=700 && widgets = 1) document.write(50) is this doable and is it the easiest way to accomplish this? I'm trying to work with XML DOM for the first time as I need to grab a value from a SOAP request. I've been following this: http://www.w3schools.com/xml/xml_parser.asp, which says modern browsers won't parse xml files from another server for security reasons. How would I got about doing this then? I've been using the price of crude oil as an example (http://www.google.com/ig/api?stock=OIL) and want code portable enough to put on something like Tumblr, so I don't think I can actually save the file locally first. Any ideas? Thanks, Zach hi, I am a newbie. Using Java script, I need to open and read CSV file. I need to read the third column values and store in an array. Please help me regarding this. Thanks, Hanumanth. I'm trying to parse out location data from XML that is passed back from Google. It currently parses the data correctly, the problem is that it grabs all of the matching tags, instead of just the first results set. Here's an example of the output. Here's the code I'm using to achieve this: Code: function(){ var url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=NewBrunswick,NJ&sensor=false'; $.ajax({url: 'proxy2.php?url='+url, type: "GET", dataType: "text", success: function ($data) {$data = $($data); lat = ($data.find('geometry').find('location').find('lat').text()); long = ($data.find('geometry').find('location').find('lng').text()); }});}); How would I change it so that it only grabs the data from the first set of results? Hello, I'm trying to parse my data from an xml file now and print it out on the page based on date from my existing code. I have that working, with each item formatted the same way on the page What I'd like to do now is alter it a bit to make the most recent (the item listed on the top of the page) formatted differently and the rest of them as it is now. Something like - (if 1st <li> then build html like this else build html like that) I hope this makes sense. Code: <?xml version="1.0" encoding="utf-8" ?> <books> <book title="CSS Mastery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/css.jpg"> <description> 08/01/2010 - Content </description> </book> <book title="Professional ASP.NET" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/asp.jpg"> <description> 08/02/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/03/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/04/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/05/2010 - Content </description> </book> </books> Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Load XML With jQuery</title> <script src="jquery-1.2.6.js" type="text/javascript"></script> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function() { /*Gets current date*/ var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var date = new Date(); /*var curr_date = d.getDate();*/ var curr_date = 3; var curr_month = date.getMonth(); var curr_year = date.getFullYear(); $.get('myData.xml', function(d){ /* $('body').append('<h1> Title</h1>');*/ $('#col-a').append('<ul id="tips"/>'); $(d).find('book').each(function(){ var $book = $(this); var title = $book.attr("title"); var description = $book.find('description').text(); var imageurl = $book.attr('imageurl'); var html = '<li class="tipItem" style="list-style:none;display: none; li">'; html += '<img class="bookImage" alt="" src="' + imageurl + '" /> '; html += '<p class="title">' + title + '</p>'; html += '<p> ' + description + '</p>' ; html += '</li>'; $('ul').append($(html)); }); var tips = $('#tips .tipItem'); tips.each(function(i) { if (curr_month == 8 && curr_date <= i){ $(this).hide(); } else { $(this).show(); } }); tips = $.makeArray(tips); tips.reverse(); $(tips).appendTo(document.getElementById('tips') ); }); }); </script> </head> <body> <div id="col-a"></div> </body> </html> Hello everybody, I am currently working on displaying KML-values of ElementTags within my KML File. I already integrated the KML file as an overlay to my Google Map. But how am I able to parse the GGeoXml-object or how am I able to parse external ("http://www.myexample.org/polygons.kml" instead of just "polygons.kml") XML-files? At the moment my code for loading the geoxml file looks like this: Code: function initialize(kmlFile) { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setUIToDefault(); map.setCenter(new GLatLng(53.763325,-2.579041), 9); // ==== Create a KML Overlay ==== if(!(kmlFile==null)){ //check if it doesnt start with "http://" if(!(kmlFile.startsWith("http://"))){ kmlFile = "http://" + kmlFile; $('kmllink').value = kmlFile; } var kml = new GGeoXml(kmlFile); //add Overlay to the googlemaps window map.addOverlay(kml); //$('subject').value = "SUBJECT"; //$('content').value = "CONTENT"; kml.gotoDefaultViewport(map); // Store center and zoom as properties of the object kml var centerKML= kml.getDefaultCenter(); var zoomKML = map.getZoom(); map.panTo(centerKML); map.setZoom(zoomKML); } } } And for parsing local XML-files this code works already: Code: function loadXML() { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","test.kml",false); xhttp.send(""); //xmlDoc=xhttp.responseXML; xmlDoc = xhttp.responseXML; var placemark=xmlDoc.getElementsByTagName("Placemark"); alert(placemark[0].getElementsByTagName("name")[0].childNodes[0].nodeValue); ajaxLoader("http://www.zki.dlr.de/mod/ext/fireModis/yesterday_en.kml","Placemark"); } My question: Is there any way to integrate parsing external xml files in any of these two functions? Best regards, TsEMaNN Hello, I am trying to assign a variable using a form value, but it returns as undefined. However, if I directly set em (uncomment them), it works. Why are my values not working? Code: <script type="text/javascript"> //lichbloom = 2; //frostlotus = 5; lichbloom = document.endlessragevalue.lichbloom.value; frostlotus = document.endlessragevalue.frostlotus.value; var endlessrage = lichbloom+frostlotus; </script> <form name="endlessragevalue" id="endlessragevalue"> Lichbloom <input type="text" size="20" name="lichbloom" value="2" /><br /> Frost Lotus <input type="text" size="20" name="frostlotus" value="5" /><br /> <script type="text/javascript">document.write(endlessrage);</script> </form> thanks for looking! I have been able to parse a JSON feed before but forwhatever reason this time around I am having a hell of a time getting it working. Here is where I am at right now. So far the script dosn't output anything. Code: <table width="100%" border="0" cellspacing="0" cellpadding="10"> <script> xhttp=new XMLHttpRequest(); xhttp.open("GET","http://biz104.inmotionhosting.com/~cox7co5/api/get_category_posts/?id=5",false); xhttp.send(""); json_data=xhttp.responseText; var parsed_data = eval('('+json_data+')'); var slug="stuff" for (i=0;i<parsed_data.count;i++) { document.write("<tr><td><a href=\"#\" class=\"showlist\">"+parsed_data.posts[i].title+"</a></td><tr>"); } </script> </table> This is an example of an email: REGION: CICSPSC1 PROGRAM: SCC23COB ABEND CODE: ASRA TRANSACTION: CORM DATE: 02/25/2010 TIME: 08:20:06 This javascript code is capable of parsing this email and return the information in the TRANSACTION: Code: var strReplace = email.body_text; strReplace = strReplace.replace(/\n/g,""); strReplace = strReplace.replace(/^REGION:\s+\w+\d+PROGRAM:\s+\w+\d+\w+/i,""); strReplace = strReplace.replace(/^\s+CODE:\s+\w+TRANSACTION:\s+/i,""); strReplace = strReplace.replace(/DATE.*$/i,""); gs.log(strReplace); So at the moment I am trying to parse this email information (below) and return the HOST: field data. Any help on this would be greatly appreciated!! Notification Type: PROBLEM Host: ka-whsym-r8 State: DOWN Address: 10.2.1.194 Info: PING CRITICAL - Packet loss = 100% Date/Time: Mon May 24 14:30:16 CDT 2010 Hi, I'm trying to write a little Javascript that would parse a CSV file that contains a name and date, and only display the name if the date matches today. Here's some example data: Name, Date Joe, 6/10/2010 Jane, 7/11/2010 If today were 6/10/2010, the output of the script would just be "Joe" Can anybody help? Thanks! Hi all, I have a simple XML file that looks something close to this: Code: <presence id="12345"> <status>in a meeting</status> <priority>1</priority> </presence> <x> <picture>blahblah</picture> </x> <x> <hash>string</hash> </x> I need javascript to pull the status from this file. Here's what I have for that: Code: <span id="login_status"></span> <span id="secondlogin_status"></span> <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","https://www/user1.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("login_status").innerHTML= xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; document.getElementById("priority").innerHTML= xmlDoc.getElementsByTagName("priority")[0].childNodes[0].nodeValue; xmlhttp.open("GET","https://www/user2.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("secondlogin_status").innerHTML= xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue; document.getElementById("second_priority").innerHTML= xmlDoc.getElementsByTagName("priority")[0].childNodes[0].nodeValue; </script> Here's my problem: If my xml file only has the one "parent" (meaning: Code: <presence id="12345"> <status>in a meeting</status> <priority>1</priority> </presence> ) this works WONDERFULLY. However, when the second and third "parents" are added (<x>), the script returns blank output in the spans. I feel almost certain my issue is related to this: http://codingforums.com/showthread.php?t=140810 but I've tried to switch that around but it doesn't seem to provide any different results. If you require a bit more info on the project itself, here's a rundown: This xml file is created by an internal chat app at my office. Each employee has their own xml file listing their current availability and status (hence "in a meeting"). This will be used to determine the availability of certain individuals in the building without having to be logged in to the chat app. That's why there's multiple xml files going to be used (roughly 10-15 in the end). So there is this string i need to parse as xml: Code: <station><code>GB0923A</code><city>ABERDEEN</city><population>215.000</population><component><name>Nitrogen dioxide (air)</name><unit>_micro;g/m3</unit></component><component><name>Nitrogen oxides (air)</name><unit>_micro;g NO2/m3</unit></component></station> Now what I do is: -use this function to create xml doc from string Code: function stringToXML(text){ if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); } else // Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(text); } return xmlDoc; } -display it in that if statement: Code: if (xmlhttp.readyState==4 && xmlhttp.status==200){ var response= xmlhttp.responseText; xmlDoc= stringToXML(response); var text=""; text= text+ xmlDoc.getElementsByTagName("city")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("code")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("population")[0].nodeValue + "<br/>"; document.getElementById("test").innerHTML = text; document.getElementById("loading").style.display = "none"; } the stirng shown at the beggining is passed to "response" (var response= xmlhttp.responseText. Now for some reason all 3 values displayed are null... I am trying to figure why for last 2hrs but i cnt see any reason why they shouldnt be the actual values of nodes in the string... Any help would be appreciated. |