Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2013, 10:13 PM   PM User | #1
aseylys
New to the CF scene

 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
aseylys is an unknown quantity at this point
Wolfram API XML Help

So I'm a little new to XML, I mean I get the gist of most of it I'm just no expert. So I'm writing this program that when asked a question it goes to the Wolfram API and asks it there, then Wolfram prints out an XML code containing the answer. Here's an example:
Question: Who is the president?
Answer:
Code:
<queryresult success="true" error="false" numpods="1" datatypes="City,Country,Leader,People,USState" timedout="" timedoutpods="" timing="1.096" parsetiming="0.191" parsetimedout="false" recalculate="" id="MSPa54631a4hg0e0c5496d8b000044bfi5giibia4e8i" auth="" host="http://www3.wolframalpha.com" server="31" related="http://www3.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa54641a4hg0e0c5496d8b00001hefhhf2fe5fbe3g&s=31" version="2.6">
<pod title="Result" scanner="Data" id="Result" position="200" error="false" numsubpods="1" primary="true">
<subpod title="">
<plaintext>Barack Obama</plaintext>
</subpod>
</pod>
<sources count="2">
<source url="http://www.wolframalpha.com/sources/LeaderDataSourceInformationNotes.html" text="Leader data"/>
<source url="http://www.wolframalpha.com/sources/PeopleDataSourceInformationNotes.html" text="People data"/>
</sources>
</queryresult>
The answer is in the <plaintext> area. So I'm wondering if there was a way, after imputing the answer that if XML had a way of just giving me the answer, like a code that would only display what is between the <plaintext> & </plaintext>?
Anyone have any clues or suggestions? Help is greatly appreciated.
aseylys is offline   Reply With Quote
Old 01-18-2013, 06:55 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
The return that you are getting (what you posted in the [code] tags) is not good xml. It hangs up in the first line at related="..." It's the second equal sign in the url that is killing this. I'm not that familiar with Wolfram API, but the little I read said you can change what you get sent back by your request structure. You should look into that.

I removed the related="..." and used everything else. I am also assuming your use ajax to get this results. What I did was to make a file called API.xml and then used this javascript to get the results:

Code:
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send('');
return xhttp.responseXML;
}
</script>
</head>

<body>
<script>
xmlDoc=loadXMLDoc("API.xml");
document.write(xmlDoc.getElementsByTagName("plaintext")[0].childNodes[0].nodeValue + "<br>");
</script>
</body>
</html>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:36 AM.


Advertisement
Log in to turn off these ads.