JavaScript - Outputting Php Rss Parser With Js
i still cant ouput correctly this php parse rss:
PHP Code: $doc = new DOMDocument(); $doc->load('http://www.lepoint.fr/content/system/rss/a_la_une/a_la_une_doc.xml'); $count_items=$doc->getElementsByTagName("item"); //echo count($count_items); $title=$doc->getElementsByTagName("item")->item(0)->getElementsByTagName("title")->item(0)->nodeValue; foreach($count_items as $value){ echo "<table border='1'><tr><td>".$value->getElementsByTagName('title')->item(0)->nodeValue."</td><td>".$value->getElementsByTagName('description')->item(0)->nodeType."</td></tr>";} using this js code : Code: <style> div#RSS{width: 700px;height: 600px;border:1px solid gray;} </style> <script> PHPscript="<?php $doc = new DOMDocument();$doc->load('http://www.lepoint.fr/content/system/rss/a_la_une/a_la_une_doc.xml');$count_items=$doc->getElementsByTagName('item');$title=$doc->getElementsByTagName('item')->item(0)->getElementsByTagName('title')->item(0)->nodeValue;foreach($count_items as $value){echo '<table border=\'1\'><tr><td>\'.$value->getElementsByTagName(\'title\')->item(0)->nodeValue.\'<\/td><td>\'.$value->getElementsByTagName(\'description\')->item(0)->nodeType.\'<\/td><\/tr>';} ?>" function ClickRSS(){ document.getElementById("link").onclick=ShowRSS } function ShowRSS(){ div=document.createElement("div"); div.id="RSS"; div.innerHTML=PHPscript; document.body.appendChild(div); } window.onload=ClickRSS; </script> <body> <a href="#no" id="link">LINK</a> </body> Similar TutorialsSay that I've got the following XML Code: <document> <block key="block1"> <p>This is a <bold>paragraph</bold></p> </block> <block key="block2"> <p>Additional paragraph</p> </block> </document> Obviously the schematics of this data and the constraints placed upon them can be described using XSD. For example, the following rules would apply: * must be a document element as the top-level parent element * must be at least one block element as a child of document * each block must have a unique key value * blocks can have 1...n p child elements. * p elements can have 0...n bold child elements What I'm looking for is an engine that executes on the client-side (JavaScript / jQuery) that can parse the XSD and flag any errors. In addition I would also need to be able to interrogate the engine in order to determine what are valid child nodes at a particular level of the XML. For example, the following types of queries might be asked of the engine: * Q: Is the overall XML valid? A: yes / no + report * Q: I'm looking at the element block (key="block2"). What are the valid child elements of this element? A: p (1...n). * Q: I'm looking at the element p in the first block (key="block1"). What are the valid child elements of this element? A: #text, bold (0...n). Determining the valid child elements of a particular element is something akin to how Visual Studio e.g. 2010 uses Intellisense. For example, given a schema Visual Studio let's you know what the valid elements are at a particular position as you type enter the XML. Finally I've mentioned XSD / XML above but we do not necessarily have to be constrained to these technologies so alternative ideas will be appreciated equally as well. Thank you for taking the time to examine my post. Hi I would like to write a parser like the one below except I would like it to take characters with the the digits like 345j, 982p0, what would I change to be able to have characters with numbers? Code: ts.addParser({ id: "digit", is: function (s, table) { var c = table.config; return $.tablesorter.isDigit(s, c); }, format: function (s) { return $.tablesorter.formatFloat(s); }, type: "numeric" }); My script runs, but it prints out to a new window. I want it to appear in the text box in the Answer <div>. I've tried using document.my_form.Answer.answerText.write() and window.document.my_form.Answer.answerText.value = " " I tried it with and without the <p></p> tags. I'm out of ideas. Can someone please help me figure this out? Code: <html> <head> <title>Magic 8 Ball</title> </head> <body> <form name="my_form"> <div id="question"> <h1>Ask your question here</h1> <input type="text" id="questionText" name="questionBox" /> </div> <div id="Answer"> <input type="submit" value="Submit" onClick="answer()"/> <h1>The magic 8 ball says:</h1> <script type="text/javascript"> function chance() { var ranNum = Math.floor(Math.random()*6); return ranNum; } function answer() { var nonsense = chance(); var reply = new Array(6); reply[0] = "Definitely"; reply[1] = "Quite possibly"; reply[2] = "Highly unlikely"; reply[3] = "Doubtful"; reply[4] = "No way!"; reply[5] = "Outlook is unclear, ask again later"; document.write('<p>' + reply[nonsense] + '</p>'); } </script> <input type="text" name="answerText" /> <input type="reset" value="Reset" /> </div> </form> </body> </html> Ok, This one has plagued me for some time now. I am parsing an XML file for a search feature. On my local machine, the code below works fine in FF, but when I upload it, I get an error stating y[0] (the root element) is undefined. I think the problem may be with my onload method but I can't be sure. Code: function importXML() { if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.onload = createTable; } else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.onreadystatechange = function () { if (xmlDoc.readyState==4) createTable(); } } else { alert('Your browser can\'t handle this script'); return; } xmlDoc.load("catalog.xml"); } // and now for the part that fails var y = xmlDoc.getElementsByTagName('data'); var dcount = 0; for (t=0;t<y[0].childNodes.length;t++) { //this is the line where FF reports the error if (y[0].childNodes[t].tagName == "record") { dcount++; } } The xml syntax is as follows Code: <data> <record> <item 1>text</item 1> <item 2>text</item 2> <item 3>text</item 3> </record> <record> <item 1>text</item 1> <item 2>text</item 2> <item 3>text</item 3> </record> </data> I just can't figure out why this works locally and not on the server. IE works fine, but then again it uses the activeXObject method so it should function differently. Hi, I have a javascript app that works fine to parse my bb_feed.xml page pasted below this message. The problem is I need to link to the script instead of including it within the web page. When I try to create the page as a .js file and link to this script from another webpage, it doesn't work. Here's the code that I used to link the .js file that I have named bb_footer.js <script language="javascript" src="bb_footer.js" type="text/javascript"></script> Is there some other way this has to be done? Thanks for any and all possible help... <html> <body> <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","bb_feed.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; var x=xmlDoc.getElementsByTagName("item"); for (i=0;i<x.length;i++) { document.write("<ul><li><a href=\""); document.write(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue); document.write("\">"); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write("</a></li></ul>"); } </script> </body> </html> Here are my Two classes and a tester. I need help outputting a sub-list of all the Highly Paid employees. public class Pay2 { private String name; private char gender; private double hours; private double payRate; /** * Constructor for objects of class Pay */ public Pay2(String n, char g, double h, double r) { // initialise instance variables name = n; gender = g; hours = h; payRate = r; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public double computeGrossPay () { return hours * payRate; } public char getGender () { return gender; } public double getRate () { return payRate; } } _____________________________ import java.util.*; public class Salary { private ArrayList theSalary; public Salary() { ArrayList theSalary = new ArrayList (); } public void addSalary (Pay2 p) { theSalary.add (p); } public double computeSalary() { double total = 0; for (int i = 0; i < theSalary.size(); i++) { Pay2 p =(Pay2) theSalary.get (i); total = total + p.computeGrossPay(); } return total; } public double computeMale() { double total = 0; for (int i = 0; i < theSalary.size();i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getGender() == 'm') total = total + p.computeGrossPay(); } return total; } public double computeFemale() { double total = 0; for (int i = 0; i < theSalary.size();i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getGender() == 'f') total = total + p.computeGrossPay(); } return total; } public int highPay(double i) { double pay = i; int number = 0; for( int s = 0; s < theSalary.size(); s++) { Pay2 p =(Pay2) theSalary.get (s); if (p.getRate() >= pay) number++; } return number; } public ArrayList highPaid(double b) { double pay = b; ArrayList a = new ArrayList(); for (int i = 0; i < theSalary.size(); i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getRate() >= pay) a.add(p); } return a; } } _____________________________________ import java.util.*; public class Tester { public static void main (String [] args) { Salary s = new Salary(); Pay2 p = new Pay2("Bob", 'm', 30, 10.50); s.addSalary(p); p = new Pay2("Jen", 'f', 30, 12.00); s.addSalary(p); p = new Pay2("Tom", 'm', 20, 9.50); s.addSalary(p); p = new Pay2("Pat", 'f', 40, 15.65); s.addSalary(p); p = new Pay2("Nick", 'm', 45, 12.00); s.addSalary(p); p = new Pay2("Mike", 'm', 35, 15.00); s.addSalary(p); p = new Pay2("Barb", 'f', 20, 25.00); s.addSalary(p); p = new Pay2("Katie", 'f', 30, 14.00); s.addSalary(p); p = new Pay2("John", 'm', 45, 12.00); s.addSalary(p); p = new Pay2("Mark", 'm', 40, 7.75); s.addSalary(p); Scanner sc = new Scanner(System.in); System.out.println("What is the threshold for high Pay?"); double a = sc.nextDouble (); double w = s.computeSalary(); double m = s.computeMale(); double f = s.computeFemale(); int h = s.highPay(a); System.out.println("The weekly salarys for all employees is $" + w); System.out.println("The weekly salarys for all males is $" + m ); System.out.println("The weekly salarys for all females is $" + f); } } Any feedback will help. Thanks, Allusive Hi, I'm really new to javascript and need help. I have a table of ingredients and a number of times they appear in a product. the table looks something like this: ingredient_01 3 ingredient_02 5 ingredient_03 8 ingredient_04 7 I need to write a script/formula/anything that will generate an output where each ingredient is output as many times as the associated number. i.e. an output has to look like this: ingredient_01 ingredient_01 ingredient_01 ingredient_02 ingredient_02 ingredient_02 ingredient_02 ingredient_02 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 Any help is appreciated. Thank you. I have the two functions below, I want to write a function that puts them into a chart, I have the chart sorted etc but just struggling with how to get the actual validated users inputs from these two functions into the chart, I've tried document.write('<td> $' + productIndex + '</td>'); into the chart but that wouldn't work anyway as there could be multiple inputs? Just need a way to get the output really. function getProductChoice(min, max) { var getProductChoice = function(min, max){ do{ var productIndex = parseInt(prompt('Enter your product choice; 0-5', '0')); } while( isNaN(productIndex) || productIndex < min || productIndex > max); }; getProductChoice(0,5); } function getProductQuantity(max) { do{ var productIndexQuantity = parseInt(prompt('How many would you like?', '0')); } while( isNaN(productIndexQuantity) || productIndexQuantity < 0 || productIndexQuantity > max); }; getProductQuantity(MAX_QUANTITY); I'm trying to insert a title and a body into a Google maps window through PHP. The body could contain double or single quotes. How do I output these so that they don't break the script? Relevant code: Code: $('#map_canvas').gmap('openInfoWindow', { 'content': '<strong><?php echo $m->marker->Title; ?></strong><br /><?php echo $m->marker->Body; ?><?php echo '<a href="./marker_info.php?id='.$m->marker->Nid.'"></a>' ?><br /><a id="m_location" href="#" data-role="button" data-icon="search" onclick="$.mobile.silentScroll(500);"></a>'}, this); Hi all, I have an issue that seems to relate to IE6 only. Tested and working in IE8 and FF3. If you go to the following page and click 'Buy Now' at the bottom of the page to submit the form the jQuery validate library error messages are displayed at the top of the page, rather than next to the corresponding form element: http://bit.ly/cc97GP Any help appreciated with this one. Seems to work fine in IE8 and FF3 as mentioned. Best Regards, Picco Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any help would be greatly appreciated! Code: <script type="text/javascript"> function loadText() { var t1=setTimeout("document.getElementById('data').innerHTML='<center><img style=\"margin-top:30px;\" src=\"loading.gif\" /></center>'",0000); var t2=setTimeout("document.getElementById('data').innerHTML='THEPAGE'",6000) } </script> The above is in the header, and I'm calling it in the html. Code: <script type="text/javascript"> document.write(loadText()); </script> in the page it displays properly, but then it also says "undefined" not sure why? anyone have any ideas? |