Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Thanked 0 Times in 0 Posts

    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?
    <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>
    <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"/>
    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.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Thanked 548 Times in 547 Posts
    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:

    <!DOCTYPE html>
    function loadXMLDoc(dname)
    if (window.XMLHttpRequest)
      xhttp=new XMLHttpRequest();
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xhttp.responseXML;
    document.write(xmlDoc.getElementsByTagName("plaintext")[0].childNodes[0].nodeValue + "<br>");


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts