NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: XML(?) problem

Eric Rank flakie at gmail.com
Fri Feb 25 20:36:16 EST 2005


I couldn't resist responding to this. XMLHTTPrequest is too cool to ignore....

I'd suggest using the DOM methods available to you for both extraction
and insertion. I find them much more friendly and clean to use than a
bunch of document.write statements. I've had pretty good luck with
them for the major mainstream browsers / platforms.

Some of the relevant players will be:

//for the response you get after making your XMLHTTPRequest.
req.responseXML.getElementsByTagName("item");
//create a new element
document.createElement('tagname')
//retreieve a node reference
document.getElementById('id');
//insert a child node
appendChild([node reference])

I created a simple directory listing app that you can check out. Be
careful where you put it though, it shows all the contents of whatever
directory the webserver can read! As a result, it's password protected
with 'password' as the password. Just put it on your server and browse
to 'directory.php'

http://lo-fi.net/blog/archive/getfile.zip

It's poorly documented, and it comes with no warranty. It also has a
problem reading dirs and files that have apostrophe's :-)

More about DOM scripting: you can see what methods and properties are
available to you with the DOM inspector that comes with Firefox
(tools>DOM Inspector). After you open it up, look in the right column
at the top. you'll seee a grid-like icon with an arrow; click that and
choose 'Javascript Object'. Then you can check out all of the
available properties and methods available on the node you have
selected in the left column of the window. It's an extremely handy
tool when debugging. It also tells you what the current DOM structure
is, regardless of your source code. So as you're building up your page
dynamically with your xmlhttprequests, the DOM inspector gives you an
accurate snapshot of the tree.

Eric Rank


On Fri, 25 Feb 2005 19:21:46 -0500, Faber Fedor <faber at linuxnj.com> wrote:
> On 25/02/05 18:45 -0500, corey szopinski wrote:
> > I read somewhere that the xml request object likes to see that the content
> > is served up as XML, so either the file extension ends in .xml or you have
> > the header set as header("Content-type: text/xml");
> 
> That did it!
> 
> Now I have to figure out how to extract the child nodes...
>



More information about the talk mailing list