some newbie XML questions

73 views
Skip to first unread message

Adityo Pratomo

unread,
Jan 28, 2011, 3:05:51 PM1/28/11
to Processing.js
hello there!

My name is Adityo. I'm a new member in this group, and eventhough I've
been playing with Processing for about 2 years now, I'm fairly recent
to this Processing.js

Anyway, enough with the intro :D I was thinking of making an internet
art installation/visualization using data from Twitter XML feed. I've
managed to did the core of the installation using Processing, and as I
want to put this on my website, I choose to use Processing.js for the
deployment. However, I have some fairly newbie questions about this:

1. How can I get XML feed from external server (or in this case,
Twitter's server)? In Processing, I can use Daniel Shiffman's
excellent Simple ML library which can receive XML feed from a URL, but
I didn't see any info about achieving it using Processing.js' XML
Element (I think it can only load xml from a file).

2. Can I get asynchronous request using XML Element? Or is there any
other way? Or should I use JavaScript for this?

3. If I decided to put this Processing.js script of my visualization
on my website should I sign the applet? Or can I use the Twitter
authentication for this? Or perhaps there's another workaround for
this?

Sorry for the long and basic questions, kinda feel there are a lot to
ask :D

Cheers :)

Anna Sobiepanek

unread,
Jan 28, 2011, 8:15:53 PM1/28/11
to proces...@googlegroups.com
Hey,
So you cannot create an XMLElement from a url like you would in Java Processing. You will have to use Javascript to get the data convert it into a string and pass it into the xmlElement when creating it. I do not understand #3 processing-js just works on the browser no Applets required. 

Anna


--
You received this message because you are subscribed to the Google Groups "Processing.js" group.
To post to this group, send email to proces...@googlegroups.com.
To unsubscribe from this group, send email to processingjs...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/processingjs?hl=en.


mediapathic

unread,
Jan 29, 2011, 4:27:12 PM1/29/11
to proces...@googlegroups.com
A little about XML and JS...
In Javascript it is pretty easy to load and parse XML, but it is waaaay
easier if you use jquery. I recommend taking a look at this:
http://think2loud.com/reading-xml-with-jquery/ it's a pretty good
tutorial on this subject. Basically you just load jquery as a library in
your page the same way you do pjs, and use their functionality for
loading xml as per that page. What you do with this data, I couldn't
tell you without seeing what you are trying to do, but I would think it
would be relatively easy to if nothing else put the data in an array and
pull it with your processing code. I've not done enough crossover
between them to say anything useful about that part but it must be feasible.

One caveat though: are you sure you want XML? In the world of web APIs
there are generally two ways of getting data, XML and JSON. XML works
but due to security issues you can't load XML from one server from
another. It's complicated but basically it comes down to this: if you
use XML you will do the same thing I did and constantly fight against
weird bugs caused by this. XML is great for local files, if you are
pulling the data separately and storing it somewhere, but if you are
trying to pull from a server every time your sketch runs I recommend you
use JSON instead, I guarantee you it will cause a lot fewer headaches
and probably be better for you in the long run. And it's not that
different, conceptually, from XML, it's essentially the same thing with
different punctuation. This tutorial
http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
is not useful for what you want to do, but has a nice illustration that
shows the relationship between XML and JSON well. Again, jquery has
great tools for pulling JSON data, my advice at the top on that one
still stands.

HTH,
--Steen

Josh Nimoy

unread,
Jan 29, 2011, 12:55:36 PM1/29/11
to proces...@googlegroups.com
you can in processing-js but it's done using regular js

if (window.XMLHttpRequest){
xhttp=new XMLHttpRequest();
}else{
// for IE 5/6
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","myfile.xml",false);
xhttp.send();
alert(http.responseXML);

//J

Jeremy Arca

unread,
Jan 29, 2011, 1:13:11 PM1/29/11
to proces...@googlegroups.com
you can parse,request xml in jquery and then pass it over to processing.

On Fri, Jan 28, 2011 at 5:15 PM, Anna Sobiepanek <anna.so...@gmail.com> wrote:

Adityo Pratomo

unread,
Jan 30, 2011, 4:31:55 AM1/30/11
to Processing.js
wow, thank you for the information. Anyway, basically what I want to
do is I want the sketch to run only once, and then it will constantly
send an XML request to Twitter say at least once every 2 hours. Why I
use XML, is because that's the one that I quite understand, never got
through JSON (stupid reason huh?) and I've managed to do this using
Processing, locally from my laptop.

So now, since I want to implement this on my website, using
Processing.js, is it better for me to use JSON? can JSON accept data
from Twitter server and store it on my website's server, while if I
use XML then it will be tricky for me to get access from another
server on a different doman?

So, principally, I can use the same concept either with JSON or XML
right? I request the JSON/XML using js and then pass it to
Processing.js isn't it?

On Jan 30, 4:27 am, mediapathic <mediapat...@gmail.com> wrote:
> A little about XML and JS...
> In Javascript it is pretty easy to load and parse XML, but it is waaaay
> easier if you use jquery. I recommend taking a look at this:http://think2loud.com/reading-xml-with-jquery/it's a pretty good
> tutorial on this subject. Basically you just load jquery as a library in
> your page the same way you do pjs, and use their functionality for
> loading xml as per that page. What you do with this data, I couldn't
> tell you without seeing what you are trying to do, but I would think it
> would be relatively easy to if nothing else put the data in an array and
> pull it with your processing code. I've not done enough crossover
> between them to say anything useful about that part but it must be feasible.
>
> One caveat though: are you sure you want XML? In the world of web APIs
> there are generally two ways of getting data, XML and JSON. XML works
> but due to security issues you can't load XML from one server from
> another. It's complicated but basically it comes down to this: if you
> use XML you will do the same thing I did and constantly fight against
> weird bugs caused by this. XML is great for local files, if you are
> pulling the data separately and storing it somewhere, but if you are
> trying to pull from a server every time your sketch runs I recommend you
> use JSON instead, I guarantee you it will cause a lot fewer headaches
> and probably be better for you in the long run. And it's not that
> different, conceptually, from XML, it's essentially the same thing with
> different punctuation. This tutorialhttp://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

sspboyd

unread,
Feb 21, 2011, 10:24:17 PM2/21/11
to Processing.js
I'm trying to do something similar. It is very easy to pull data from
twitter using jQuery's $.getJSON. The part I'm trying to figure out is
how to pass that data to my processing.js code. I'm not as familiar
with javascript as I am with Processing/Java.

The options I've seen are to either:
a) reference the returned results directly (not sure how to do that
yet)
b) attach a variable to the DOM window object and pass the data as a
property eg window.PassVar.dataFromTwitter
c) make my jquery $.getJSON call from within the processing.js code

Again, I don't know if any of those work or what the pro/cons would be
between them. I'm guessing this will be obvious once I've seen how it
works but until then I'm fumbling around a bit.

I've just found the PomaxGuide on the Processingjs site
http://processingjs.org/reference/articles/PomaxGuide#json which
should help.

Stephen


On Jan 30, 4:31 am, Adityo Pratomo <quietdi...@gmail.com> wrote:
> wow, thank you for the information. Anyway, basically what I want to
> do is I want the sketch to run only once, and then it will constantly
> send an XML request to Twitter say at least once every 2 hours. Why I
> use XML, is because that's the one that I quite understand, never got
> through JSON (stupid reason huh?) and I've managed to do this using
> Processing, locally from my laptop.
>
> So now, since I want to implement this on my website, using
> Processing.js, is it better for me to use JSON? can JSON accept data
> from Twitter server and store it on my website's server, while if I
> use XML then it will be tricky for me to get access from another
> server on a different doman?
>
> So, principally, I can use the same concept either with JSON or XML
> right? I request the JSON/XML using js and then pass it to
> Processing.js isn't it?
>
> On Jan 30, 4:27 am, mediapathic <mediapat...@gmail.com> wrote:
>
>
>
>
>
>
>
> > A little about XML and JS...
> > In Javascript it is pretty easy to load and parse XML, but it is waaaay
> > easier if you use jquery. I recommend taking a look at this:http://think2loud.com/reading-xml-with-jquery/it'sa pretty good

sspboyd

unread,
Feb 23, 2011, 11:41:33 PM2/23/11
to Processing.js
Following up on my own question. Here's what I worked out.
This is a modified version of the example on the Pomax Guide page on
the site.

Create function called getNewTweets that runs when the page has fully
loaded, and can be called multiple times based on user interaction.


function getNewTweets(canvasId) {
// Create a var referencing the Processingjs canvas.
var pjs = Processing.getInstanceById(canvasId);

// Use jQuery's getJson function to get search results from
twitter.
$.getJSON("http://search.twitter.com/search.json?&callback=?",
{
q: "nhl",
rpp: '100',
result_type: "recent",

// Using the since_id parameter to make sure I'm only
getting new posts on subsequent calls.
since_id: pjs.sinceId
},
function(data) {
pjs.sinceId = data.max_id+1; // +1 so we don't get the same max_id
tweet. need better solution here

// Iterate through each item in the 'results' node and
calling the addTweet() method in the processingjs sketch.
$.each(data.results, function(i,item){
pjs.addTweet(item.from_user, item.id, item.text)
});
});
> > > easier if you use jquery. I recommend taking a look at this:http://think2loud.com/reading-xml-with-jquery/it'sapretty good
Reply all
Reply to author
Forward
0 new messages