[thelist] XML fragment into DOM

Roderick A. Anderson raanders at mailporter.net
Thu Jul 14 00:32:22 CDT 2005



Jeff Howden wrote:

> Please tell me that you didn't try to write the script for doing the
> XMLHTTPRequest yourself.  I say this because there are several very good
> libraries out there that already abstract the browser differences for you.


If you insist I'll admit I didn't.  :-)  I grabbed the code from an 
article on XML.com and saw several variations of it at other sites.

>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>>1. A full XHTML document that is opened in another
>>   window,
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> Doable, but why not just request the XHTML from the server directly rather
> than use XHR and populate a popup?

Strange situation in that I need to make the call from within a form 
without submitting the form or triggering the javascript validation.  It 
works on one site but not the other.  As I think I've mentioned before I 
get very _pretty_ pages with tons of presentation markup and using 
tables for layout that I have to stuff forms into.  So even when I think 
I'm using the same html, css and javascript it may not be so.

>>2. a XML fragment that ( hopefully ) could be stuck
>>   right into the document at the correct place,
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> This is one of the more common uses.

Feeling better all the time!

>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>>3. an Object or the code to create the object and do an
>>   eval on that (?), and lastly
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> I would recommend *against* this approach.  Wherever possible, avoid eval()
> like the plague.  There's a reason it sounds so similar to the word evil.

Gotcha!  I remember seeing an article today that mentioned this.  eval 
is/can be a performance pig.

>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>>4. some custom data format.
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> Most often XHR is used to run a "function" on a server, taking the result of
> that function and doing something with it in the document making the XHR.
> Most often, the datatypes returned by the server are booleans, integers,
> floats, and strings.  Once in a while you'll have the need for something
> more complex like an array or complex object.  Once you depart from the
> simple data types though, the issues become far more complex to work out, no
> pun intended.

This ties back to my need to modify/add-to a selection list and another 
where I return the username being available or some optional values.  ( 
Saw an article on this today on ALA.

>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>>My preference is some ( builtin/loadable? ) function to
>>turn an xml fragment into part of the DOM.
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> If the fragment contains nothing but standard XHTML, inserting that fragment
> is as easy as finding the element you wish to make the parent of the
> fragment and stuffing it into that element using its innerHTML property.

Ok I saw this ( innerHTML ) once or twice today but never read a good 
explanation of what it does and how to use.  I'll pull the 
xmlHTTPRequest references I found and get more familiar.

> Purists will gag reading that and suggest that you loop over the structure
> of the fragment inserting the various pieces using calls to the
> createElement() and appendChild() methods of the document object.

Former COBOL/FORTRAN/Pascal programmers I'm sure.  I've done most of my 
work for the last 8 years or so in perl.  If there is a fast way to do 
it and it is understandable/maintainable I use it.

>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>>Suggestions or even better pointers ( my searches --
>>five pages into a google search ) didn't help.
>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 
> 
> Neuromancer is a *very* robust XHR library.

Humm.  I didn't run across this one.  Of course I wasn't searching for 
*libraries* either.  I did but a copy of "The Browser Book" following a 
link from your site which distracted me until I read your message from 
looking at your site.  Interesting code and articles.

BTW list, I go into so much detail and ramble on in the hopes of helping 
someone later on that is searching the list archives.  I have picked up 
quite a bit of information from rambling threads in lists myself.

Thanks Jeff for the insights and recommendations.


Rod
-- 
---
[This E-mail scanned for viruses by Declude Virus]



More information about the thelist mailing list