0

XML API parsing

Hi,
I am trying to parse some XML data from a live FTP Server. I am unable to parse the elements i require into the widget screen(although i am just able to print it on the terminal). Is there any documentation that could help me achieve this (there are examples in the document but no concrete example on parsing step by step unless i am missing something).

My code currently is currently just (without parsing any element) in the updateview: function

var request = new XMLHttpRequest();
request.open( "GET", "http://www.website.com/test.xml", false );
request.send();
print("doing this!!!!!");
print( request.responseXML.toXML() );
print("doint this too !!!!!!");


I do realize currently i am just printing it into the terminal. For example say i have a parent element named 'bookstore' and child named 'name' how can i parse the value of text of the first element of 'name' ?i tried something like

element = request.evaluate( "bookstore/name" );
text = element.item(0).firstChild.data;
document.write(text);

but it just wont recogonize document.write. I am pretty new to JavaScript and XML sad.gif

by
12 Replies
  • You are trying to make accessing the node to hard. The below would the the correct XPath.

    CODE
    element = request.evaluate( "string(bookstore/name)" );
    //Need to pull out the string()


    Also, "document.write()" should be a "print()"
    0
  • Also, it is very useful to hand the request to object - like below. I also noticed you are not parsing the XML...

    CODE
    var request = new XMLHttpRequest();
    request.open( "GET", "http://www.website.com/test.xml", false );
    request.send();
    var myXML = XMLDOM.parse( request.responseXML.toXML() );
    var element = myXML.evaluate( "string(bookstore/name)" );
    //Need to pull out the string()
    print(element);
    0
  • QUOTE (WidgetRealm @ Jul 31 2009, 07:08 AM) <{POST_SNAPBACK}>
    Also, it is very useful to hand the request to object - like below. I also noticed you are not parsing the XML...

    CODE
    var request = new XMLHttpRequest();
    request.open( "GET", "http://www.website.com/test.xml", false );
    request.send();
    var myXML = XMLDOM.parse( request.responseXML.toXML() );
    var element = myXML.evaluate( "string(bookstore/name)" );
    //Need to pull out the string()
    print(element);



    Firstly thank you very much, i am able to get it into my terminal. Now my second question is WidgetRealm, how do i get this parsed element into the widget screen ? do i create a textbox in createview ? if so how do i connect that text box to this parsed data?
    Thank you very much for your help guys. appreciate it.
    0
  • Hi krish,
    You can check example widget 'NewsTV' (Yahoo News). On Ubuntu it is located here:
    /usr/local/Konfabulator/TV/Widgets/NewsTV.widget/
    In file /Contents/Javascript/core/API.js you can see example of using URL object to load XML/JSON; check WDK documentation aswell

    QUOTE (krish . @ Jul 31 2009, 05:36 AM) <{POST_SNAPBACK}>
    element = request.evaluate( "bookstore/name" );
    text = element.item(0).firstChild.data;

    It is shorter to use
    CODE
    text = request.evaluate('string(bookstore/name)');

    Check WDK documentation, there are good examples of parsing xml

    QUOTE (krish . @ Jul 31 2009, 05:36 AM) <{POST_SNAPBACK}>
    I am unable to parse the elements i require into the widget screen(although i am just able to print it on the terminal). Is there any documentation that could help me achieve this (there are examples in the document but no concrete example on parsing step by step unless i am missing something).

    To display something on "widget screen" you can create Text element and populate it with your text :)Cheers, Nikola
    0
  • QUOTE (georgi.dinchev @ Jul 31 2009, 07:05 AM) <{POST_SNAPBACK}>
    Hi krish,
    You can check example widget 'NewsTV' (Yahoo News). On Ubuntu it is located here:
    /usr/local/Konfabulator/TV/Widgets/NewsTV.widget/
    In file /Contents/Javascript/core/API.js you can see example of using URL object to load XML/JSON; check WDK documentation aswell


    It is shorter to use
    CODE
    text = request.evaluate('string(bookstore/name)');

    Check WDK documentation, there are good examples of parsing xml


    To display something on "widget screen" you can create Text element and populate it with your text :)Krish
    0
  • I would start by making sure you understand the WDK, the DOM, and all the elements. Sending & receiving is the easy part of building a widget, the display and design elements are where you should be focusing all efforts now. :)
    0
  • QUOTE (WidgetRealm @ Jul 31 2009, 12:32 PM) <{POST_SNAPBACK}>
    I would start by making sure you understand the WDK, the DOM, and all the elements. Sending & receiving is the easy part of building a widget, the display and design elements are where you should be focusing all efforts now. :). thanks anyways .
    0
  • QUOTE (georgi.dinchev @ Jul 31 2009, 07:05 AM) <{POST_SNAPBACK}>
    Hi krish,
    You can check example widget 'NewsTV' (Yahoo News). On Ubuntu it is located here:
    /usr/local/Konfabulator/TV/Widgets/NewsTV.widget/
    In file /Contents/Javascript/core/API.js you can see example of using URL object to load XML/JSON; check WDK documentation aswell


    It is shorter to use
    CODE
    text = request.evaluate('string(bookstore/name)');

    Check WDK documentation, there are good examples of parsing xml


    To display something on "widget screen" you can create Text element and populate it with your text :)Max
    0
  • Re: News widget included in old WDKs.

    Please do not use it as a basis for your widget development. Best practices have changed and using old code is a quick way to failure.

    -Jeremy
    0
  • Hi,
    I want to create news widget, what do i get anything ready? And please tell me how to convert .widget directory to .widget file to upload http://gallery.tv.widgets.yahoo.com/publisher/?
    Thanks,
    Sarah
    0
  • Hi Sarah

    zip -r MyWidget.zip MyWidget.widget
    mv MyWidget.zip MyWidgetToUpload.widget

    This is all clearly spelled out in the documentation. I highly recommend you take a glance at it. :)-Jeremy
    0
  • QUOTE (Jeremy Johnstone @ Jan 8 2010, 11:42 AM) <{POST_SNAPBACK}>
    Hi Sarah

    zip -r MyWidget.zip MyWidget.widget
    mv MyWidget.zip MyWidgetToUpload.widget

    This is all clearly spelled out in the documentation. I highly recommend you take a glance at it. :)I'll see to it more carefully. Thank you very much.
    0

Recent Posts

in General - Yahoo! TV Widgets