trinaryatom Posted July 15, 2011 Share Posted July 15, 2011 I am wondering if i can change this code. <events> <month> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> </month> <month> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> </month> <month> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> <day> <text>blah</text> <discrip>blah blah blah</discrip> </day> </month></events> Edit: Edit: Well i think i found a pretty good alternative. So no need to find out about this. But i am still curious to figure this out.Here it is <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","test.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML;y=2//Monthx=1//Dayfunction displayTEXT(){ texttitle=(xmlDoc.getElementsByTagName("month")[y-1].getElementsByTagName("discrip")[x-1].childNodes[0].nodeValue); textdate=(xmlDoc.getElementsByTagName("month")[y-1].getElementsByTagName("text")[x-1].childNodes[0].nodeValue); textdraw=textdate + "<br/>" + texttitle + "<br/>"; document.write(textdraw);}displayTEXT()</script> For some reason it doesn't work in IE .. i think its because i haven't uploaded to an external website. Link to comment Share on other sites More sharing options...
trinaryatom Posted July 16, 2011 Author Share Posted July 16, 2011 Slightly different than before, but i need help figuring out whats wrong here. Its bothering me so much.I have the following code function displayCalander(){ 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","xmldata/dates.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; //iMonth=7//Month //iEvent=1//Event //iDay=15//Day var now = new Date(); var curCMonth = now.getMonth() + 1; var curCDay = now.getDate(); var curCYear = now.getFullYear(); var mm=1; var mmn=1; //Month Memory = "days","day of first day 0-6" - Calendar var monthm = { 2010: new Array( new Array("9","6"),//Month 0 new Array("31","6"),//January 1 new Array("28","2"),//February new Array("31","2"),//March new Array("30","5"),//April new Array("31","0"),//May new Array("30","3"),//June new Array("31","5"),//July new Array("31","1"),//August new Array("30","4"),//September new Array("31","6"),//October new Array("30","2"),//November new Array("31","4")),//December 12 2011: new Array( new Array("9","6"),//Month 0 new Array("31","6"),//January 1 new Array("28","2"),//February new Array("31","2"),//March new Array("30","5"),//April new Array("31","0"),//May new Array("30","3"),//June new Array("31","5"),//July new Array("31","1"),//August new Array("30","4"),//September new Array("31","6"),//October new Array("30","2"),//November new Array("31","4")),//December 12 2012: new Array( new Array("9","6"),//Month 0 new Array("31","0"),//January 1 new Array("29","3"),//February new Array("31","4"),//March new Array("30","0"),//April new Array("31","2"),//May new Array("30","5"),//June new Array("31","0"),//July new Array("31","3"),//August new Array("30","6"),//September new Array("31","1"),//October new Array("30","4"),//November new Array("31","6")),//December 12 2013: new Array( new Array("9","6"),//Month 0 new Array("31","2"),//January 1 new Array("28","5"),//February new Array("31","5"),//March new Array("30","1"),//April new Array("31","3"),//May new Array("30","6"),//June new Array("31","1"),//July new Array("31","4"),//August new Array("30","0"),//September new Array("31","2"),//October new Array("30","5"),//November new Array("31","0"))//December 12 } var mmNowDay=monthm[curCYear][curCMonth-1][0]-monthm[curCYear][curCMonth][1]+1; var mmFixDay=monthm[curCYear-1][12][0]-monthm[curCYear][curCMonth][1]+1; dayNamesString=new Array("S","M","T","W","T","F","S"); for(r=0;r<=6;r++) { if(r==0) { document.write("<div class=\"calndtrow\">"); } else { document.write("<div class=\"calndmrow\">"); } for(c=0;c<=6;c++) { if(r==0) { document.write("<div class=\"calnamday\">"); document.write(dayNamesString[c]); } else if (r==1 && c < monthm[curCYear][curCMonth][1]) { if(curCMonth==1) { document.write("<div class=\"callatday\">"); document.write(mmFixDay); mmFixDay++; } else { document.write("<div class=\"callatday\">"); document.write(mmNowDay); mmNowDay++; } } else if (r>=1 && monthm[curCYear][curCMonth][0]>=mm) { xmlname=xmlDoc.getElementsByTagName("month")[curCMonth].getElementsByTagName("day")[mm-1].getElementsByTagName("name"); if (curCDay==mm) { if (xmlname.length==0) { document.write("<div class=\"caltoyday\">"); } else { document.write("<div class=\"caltoydayevent\">"); } } else { if (xmlname.length==0) { document.write("<div class=\"calnowday\">"); } else { document.write("<div class=\"calnowdayevent\">"); } } document.write(mm); mm++; } else { document.write("<div class=\"calnxtday\">"); document.write(mmn) mmn++; } document.write("</div>"); } document.write("</div>"); }} The chunk of code here pertaining to the xml doesn't work at all. It always defaults to the 'else' in the argument even if i change the 'if' to >=1 and swap them. it still defaults to the else statement. else if (r>=1 && monthm[curCYear][curCMonth][0]>=mm) { xmlname=xmlDoc.getElementsByTagName("month")[curCMonth].getElementsByTagName("day")[mm-1].getElementsByTagName("name"); if (curCDay==mm) { if (xmlname.length==0) { document.write("<div class=\"caltoyday\">"); } else { document.write("<div class=\"caltoydayevent\">"); } } else { if (xmlname.length==0) { document.write("<div class=\"calnowday\">"); } else { document.write("<div class=\"calnowdayevent\">"); } } document.write(mm); mm++; } Here is an example of the xml file i have. <calander>... <month number="7" name="July"> <day date="1"> </day> <day date="2"> </day> <day date="3"> </day> <day date="4"> </day> <day date="5"> </day> <day date="6"> </day> <day date="7"> </day> <day date="8"> <event> <name>Month 7 Day 15</name> <body>Event 1</body> </event> <event> <name>Month 7 Day 15</name> <body>Event 2</body> </event> </day> <day date="9"> </day> <day date="10"> </day> <day date="11"> </day> <day date="12"> </day> <day date="13"> </day> <day date="14"> </day> <day date="15"> <event> <name>Month 7 Day 15</name> <body>Event 1</body> </event> <event> <name>Month 7 Day 15</name> <body>Event 2</body> </event> </day> <day date="16"> </day> <day date="17"> </day> <day date="18"> </day> <day date="19"> </day> <day date="20"> </day> <day date="21"> </day> <day date="22"> <event> <name>Month 7 Day 15</name> <body>Event 1</body> </event> <event> <name>Month 7 Day 15</name> <body>Event 2</body> </event> </day> <day date="23"> </day> <day date="24"> </day>... The weird thing is that the test file (proof of concept) i created worked perfectly.Here is that example. <!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></head><body><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","xmldata/dates.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML;iMonth=7//MonthiEvent=1//EventiDay=15//Dayxmlname=xmlDoc.getElementsByTagName("month")[iMonth-1].getElementsByTagName("day")[iDay-1].getElementsByTagName("name");xmlbody=xmlDoc.getElementsByTagName("month")[iMonth-1].getElementsByTagName("day")[iDay-1].getElementsByTagName("body");if(xmlname.length>=1) { for (i=0;i<xmlname.length;i++) { document.write(xmlname[i].childNodes[0].nodeValue); document.write("<br />"); document.write(xmlbody[i].childNodes[0].nodeValue); document.write("<br />"); document.write("<br />"); } }else { document.write("No Events"); }</script></body></html> So how do i fix that if .. else statements with the xml in it.Edit:Fixed it. Some where.. I'm not sure where the 0 isn't included into something. so in order to fix it. I had a part of the code altered to this. xmlname=xmlDoc.getElementsByTagName("month")[curCMonth-1].getElementsByTagName("day")[mm-1].getElementsByTagName("name");xmlbody=xmlDoc.getElementsByTagName("month")[curCMonth-1].getElementsByTagName("day")[mm-1].getElementsByTagName("body"); Just added the -1 to the curCMonth.P.S. I wonder if my small endeavors for knowledge was any help to anyone else. Because if you know my username, and you've seen my previous posts, then you would have seen that I usually end up posting a question and then answering it myself. Its almost like this forum is a therapy. So I'm sorry if any takes this as spam. I had no such intention. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.