0

managing xml with yql

hi guys!
i have put this code between the execute tab:
<execute>
var url = "http://dblp.uni-trier.de/search/author?xauthor=stefano ceri";

var xmlaut = y.rest(url).accept('text/xml').get().response;
var att_author = xmlaut.authors.author[0].@urlpt;

</execute>

so the problem is that the console says to me there's an error because xmlaut is not an xml element. but i have also proved to use these:

var xmlaut = y.rest(url).accept('text/html').get().response;
/*as written at this page http://www.yqlblog.net/ in the end of the page:
"YQL Execute: y.rest(uri) now parses HTML documents and returns an E4X object if the accept header is set to “text/html”.

y.rest("http://finance.yahoo.com/q?s=yhoo").accept('text/html').get().response"
*/

or also i proved only this:
var xmlaut = y.rest(url).get().response;

and the results are the same. why? how can i check the type of this variable?

i thought it was a string, so i proved this:

var xmlaut = y.rest(url).accept('text/xml').get().response;
var a= new XML(xmlaut);
var att_author = a.authors.author[0].@urlpt;

but also this solution is wrong.
so in the end what's wrong?

by
2 Replies
  • QUOTE (Samuele @ Apr 14 2010, 01:21 AM) <{POST_SNAPBACK}>
    hi guys!
    i have put this code between the execute tab:
    <execute>
    var url = "http://dblp.uni-trier.de/search/author?xauthor=stefano ceri";

    var xmlaut = y.rest(url).accept('text/xml').get().response;
    var att_author = xmlaut.authors.author[0].@urlpt;

    </execute>

    so the problem is that the console says to me there's an error because xmlaut is not an xml element. but i have also proved to use these:

    var xmlaut = y.rest(url).accept('text/html').get().response;
    /*as written at this page http://www.yqlblog.net/ in the end of the page:
    "YQL Execute: y.rest(uri) now parses HTML documents and returns an E4X object if the accept header is set to “text/html”.

    y.rest("http://finance.yahoo.com/q?s=yhoo").accept('text/html').get().response"
    */

    or also i proved only this:
    var xmlaut = y.rest(url).get().response;

    and the results are the same. why? how can i check the type of this variable?

    i thought it was a string, so i proved this:

    var xmlaut = y.rest(url).accept('text/xml').get().response;
    var a= new XML(xmlaut);
    var att_author = a.authors.author[0].@urlpt;

    but also this solution is wrong.
    so in the end what's wrong?


    First of all please post a link to your full table - it's easier to see what the issues may be. Have you made sure that the Javascript is inside a CDATA section for example?

    You don't need to "create" an XML object - it's already XML coming back from your remote data source and YQL will do the work for you:

    var xmlaut = y.rest(url).get().response;
    var att_author = xmlaut.authors.author[0].@urlpt;

    should work IF the y.rest() call is succeeding. If the service is throwing a 404 then it typically won't be getting XML back but a web page.

    Jonathan
    0
  • QUOTE (Jonathan @ Apr 15 2010, 08:09 AM) <{POST_SNAPBACK}>
    First of all please post a link to your full table - it's easier to see what the issues may be. Have you made sure that the Javascript is inside a CDATA section for example?

    You don't need to "create" an XML object - it's already XML coming back from your remote data source and YQL will do the work for you:

    var xmlaut = y.rest(url).get().response;
    var att_author = xmlaut.authors.author[0].@urlpt;

    should work IF the y.rest() call is succeeding. If the service is throwing a 404 then it typically won't be getting XML back but a web page.

    Jonathan


    ok here is the link: http://onalimonalim.altervista.org/tesi/PROVA1_-_Copia.xml

    the problem coud be generated by the fact the xml returned don't have a tag with an xmlns attribute that matches with the default namespace?
    0

Recent Posts

in YQL