Jump to content

Converting XML to JSON?


Alright, I made a post like this before trying to learn JSON, and I'm still terrible at it. I took a few days and can't seem to get it. This code is for a class so not for serous use or anything, just need to know how to do this. 

I need this XML to work in JSON. I can make a JSON to display info in an alert, but that's all right now. I need help with this. I can post a link to my JSON for download if anyone needs it. Sorry it's not spaced properly, I do that last. 

So here is the XML I got working. 




<?xml version="1.0" encoding="utf-8"?><tasks><task><aname>#1 Practice Review</aname><duedate>Monday</duedate><details>~20 minutes to get your best score 2 perfects </details><time>20mins</time> <atime>15mins</atime> <rating>ALL DONE</rating> </task><task><aname>#2 SHARE access to Game One Surveys</aname><duedate>Monday</duedate><details>Create a Spreadsheet summary</details><time>20mins</time> <atime>15mins</atime> <rating>ALL DONE</rating> </task><task><aname>#3 Prep work: Tech Talk</aname><duedate>Monday</duedate><details>Complete exploration before break Monday</details><time>1Hr</time> <atime>1Hr20-30mins</atime> <rating>ALL DONE</rating> </task><task><aname>#4 Review team prof outreach letters"</aname><duedate>Whensday</duedate><details>Download the Zipped File</details><time>1Hr</time> <atime>1Hr30Mins</atime> <rating>ALL DONE</rating> </task><task><aname>#5 JSON exploration</aname><duedate>Thersday</duedate><details>Part 1: Explore JSON</details><time>1Hr</time> <atime>1Hr30Mins</atime> <rating>ALL DONE</rating> </task><task><aname>#6 modeling, weekly tasks as source</aname><duedate>Friday</duedate><details>Upload Txt files to moodle</details><time>3Hr</time> <atime>2Hrs</atime> <rating>50%</rating> </task></tasks>


<!DOCTYPE html><html><h1>Weeks Tasks</h1><head><script>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","xmlfile2.xml",false); //grabs the file thing xmlhttp.send();xmlDoc=xmlhttp.responseXML; x=xmlDoc.getElementsByTagName("task");  //name of the chunks of tasksi=0;function displayTask() // the start of loop thing{aname=(x[i].getElementsByTagName("aname")[0].childNodes[0].nodeValue);duedate=(x[i].getElementsByTagName("duedate")[0].childNodes[0].nodeValue);details=(x[i].getElementsByTagName("details")[0].childNodes[0].nodeValue);time=(x[i].getElementsByTagName("time")[0].childNodes[0].nodeValue);atime=(x[i].getElementsByTagName("atime")[0].childNodes[0].nodeValue);rating=(x[i].getElementsByTagName("rating")[0].childNodes[0].nodeValue);txt="Task: "+ aname +"<br>Due: "+ duedate +"<br>Details: "+ details +"<br>ET: "+ time +"<br>Time: "+ atime +"<br>Rating: "+ rating; document.getElementById("showTask").innerHTML=txt;}function next() //next button{if (i<x.length-1)  {  i++;  displayTask();  }}function previous() // back button{if (i>0)  {  i--;  displayTask();  }}</script></head><body onload="displayTask()">  <!-- the var name !--><div id='showTask'></div><br> <!-- same as name above !--><input type="button" onclick="previous()" value="<<" /><input type="button" onclick="next()" value=">>" /></body></head> </html>
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now