[Lvlug] java script

Aaron Cordova basicasm at hotmail.com
Sun Aug 16 13:37:42 PDT 2009



The dot notation is what I was expecting to find when I started using javascript. Kinda disappointing to find out that you have to access the object the long way. I'll see if I can find a serialization library but I doubt I'll have much luck. Thanks for your help.

> Date: Sun, 16 Aug 2009 07:38:12 -0700
> Subject: Re: [Lvlug] java script
> From: brian.e.munroe at gmail.com
> To: basicasm at hotmail.com
> 
> From what you've shown me below, it seems like this is probably about
> the best your going to do.  That is just the way SAX parsing looks.
> Being verbose isn't a bad thing though, and I would definitely not
> consider what you've written 'sloppy' by any means - I was able to
> quickly glance over it and figure out what was going on rather easily.
> 
> The only other option I can offer is to try and find a XML->JavaScript
> serialization library (I didn't have any luck) that allows you to take
> something like:
> 
> <result id="1">
> <name>Brian</name>
> </result>
> 
> and get a JavaScript object that looks like:
> 
> document.write(result.id) // prints 1
> document.write(result.name) // prints brian
> 
> But I would seriously consider emitting JSON instead of XML, since all
> the major JavaScript libraries out there seem to support it better
> then XML.
> 
> -- brian
> 
> 
> On Sat, Aug 15, 2009 at 7:19 PM, Aaron Cordova<basicasm at hotmail.com> wrote:
> > I made a live search page for my site, the xml I get back is pretty light
> > since it is almost a constant query when someone is searching.
> >
> > Here is the code:
> >
> > //load result collection into xmlResults
> > var xmlResults = request.responseXML.getElementsByTagName("result");
> >
> > then I loop through xmlResults to determine how many 'results' I have and
> > build up html table. Where I'm wondering if things can be done better is in
> > this loop. I know that xmlResults is a collection and I need to access each
> > each object to get at the interesting data I want to display.
> >
> > for(var x=0; x<reservations.length;x++)
> > {
> >       var y = list.insertRow(0);
> >
> >       var res = reservations[x];
> >
> >       var dTxt =
> > reservations[x].getElementsByTagName("text")[0].childNodes[0].nodeValue;
> >
> >       var dPage =
> > reservations[x].getElementsByTagName("page")[0].childNodes[0].nodeValue;
> >       var dDate =
> > reservations[x].getElementsByTagName("date")[0].childNodes[0].nodeValue;
> >
> > }
> >
> > What seems sloppy is the
> > getElementsByTagName("tag")[0].childNodes[0].nodeValue. There has to be
> > simpler way to get at the data than having to write a paragraph for each
> > statement.
> >
> >> Date: Sat, 15 Aug 2009 07:38:42 -0700
> >> From: brian.e.munroe at gmail.com
> >> To: lvlug at lvlug.org
> >> Subject: Re: [Lvlug] java script
> >>
> >> On Sat, Aug 15, 2009 at 4:04 AM, <krux at thcnet.net> wrote:
> >>
> >> >
> >> > I've found that for most things I'm using javascript for, working with
> >> > XML
> >> > input/output is far too much overhead, and can usually be done simpler
> >> > with
> >> > some CSV or simmilar data.
> >> >
> >>
> >> I've given up trying to process XML and anytime I would have used it,
> >> I now produce / consume JSON [1] instead. The JavaScript libraries
> >> that I use (for example, Prototype [2]) have built in functions for
> >> handling it.
> >>
> >> But anyway, post your code / questions and we'll try and help.
> >>
> >> -- brian
> >>
> >> [1] - http://www.prototypejs.org/learn/json
> >> [2] - http://www.prototypejs.org/
> >> _______________________________________________
> >> Sent via the Lvlug mailing list Lvlug at lvlug.org
> >> Set options or unsubscribe at http://lvlug.org/mailman/listinfo/lvlug
> >> The Lvlug mailing list is hosted courtesy of LasVegas.Net
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lvlug.org/pipermail/lvlug/attachments/20090816/96e055db/attachment.htm 


More information about the Lvlug mailing list