Title: Message

No, it’s available.  You might have to say responseXML.documentElement (not sure, but I always do and it works).  Oh, and you could try changing ‘get’ to ‘post’.  I’ve always had moderate to bad success in IE with ‘GET’ requests on Ajax.  Even with no arguments, sometimes IE just chokes on ‘GET’.  Haven’t really researched why it does that, but ‘POST’ has fixed it in every case.

 

If you look through the archives, I posted a script that takes an xml document and parses it into a nested _javascript_ hash, for quick and easy access to nested tags in JS.  Might be useful to you, might not.

 

Source is here:

http://greg.kathihill.com/content/jbhv/web/default/js/xml_doc.js

 

It doesn’t handle every type of XML tag, so you might need to expand it to cover more.

 

Example of usage:

 

  show: function (response) {
    var xmlDoc = new XMLDoc(response.responseXML.documentElement);
    var results = xmlDoc.asHash();
    if (results.found && results.found.length > 0) {
      // any <found> tags are included in this array, it’s always an array, even if it has just one element
      // attributes and text-only nodes are included as text, so results.found[0].id could be:
      // <found id=”1” /> or <found><id>1</id></found>
    }
  }

 

Anyhoo, if that helps, use it.  If it doesn’t, then bugger off J  I find it simplifies a lot of code for me.

 

Greg

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sam
Sent: Friday, July 28, 2006 11:17 AM
To: rails-spinoffs@lists.rubyonrails.org
Subject: RE: [Rails-spinoffs] XML Question

 

 

... is the responseXML below available only in Mozilla?  I get nada in IE.

 

Sam

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kjell Bublitz
Sent: Monday, July 24, 2006 4:19 PM
To: rails-spinoffs@lists.rubyonrails.org
Subject: Re: [Rails-spinoffs] XML Question

I don't understand your question right, but in some ways this understanding seems to be correct.
Have you just tried to request the xml document with the ajax class and had a look into responseXML ?

Here is how i do it. (copied from my recent project):

new Ajax.Request(tplpath + 'system/workdir/blocks.xml', {
            method:'get', requestHeaders:['cache-control','no-cache','pragma','no-cache'],
            onComplete:function(xmlresult) {
                if( xmlresult.responseXML.firstChild.nodeName == 'bloxpress') { // check if first child is as expected
                    Bloxpress.blocksParse(xmlresult.responseXML); // pass the responseXML to a function
                } else {
                    var blockMenuDiv = Builder.node('div', {id:'contentmenu', style:'display:none'},['No Blocks available']);
                    $(blockMenuTarget).appendChild(blockMenuDiv);
                    Bloxpress.blocksMenu = $('contentmenu');
                }
            }
        });


2006/7/24, Sam <[EMAIL PROTECTED] >:

If this XML file isn't a DOCTYPE (not a html/body/tag document), should I expect Ajax responseXML to build out an xml-doctree or should I move on to xPath?

 

Sam

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Kjell Bublitz
Sent: Monday, July 24, 2006 11:37 AM
To: rails-spinoffs@lists.rubyonrails.org
Subject: Re: [Rails-spinoffs] XML Question

humm.. as far as i know if your server delivers an XML file as text/xml or something similar then Ajax.request will fill responseXML which contains the xml-doctree. With that you can use the common DOM functions to wade through all the data and then fill your elements as you like.

Hope this helps.

2006/7/24, Sam <[EMAIL PROTECTED]>:

 

I've got an XML file which is pretty well structured.  I need to retrieve specific elements from that file to fill out empty HTML elements on a page.

 

I think what I need is xPath?  Or - is that overkill?  Is there some easier way to locate an XML element?

 

What I have in mind is pulling the XML file using Ajax, then xPath to get the bits I need.

 

Am I on the right path and does prototype have an xPath capability?

 

Sam


_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

 


_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

 

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to