Hello,
Can you give me a jumpstart how to parse the response xml file?
I tried
var ajax = new Ajax.Request(url,{method: ''get'', parameters:
params,
onSuccess: handlerFunc, onFailure: reportError});
var handlerFunc = function(t) {
var xmlDoc = t.responseXML.documentElement;
????????????????????????????
city = ?
state = ?
alert(city);
}
xml:
<?php
header("Content-Type: application/xml; charset=utf-8");
?>
<?xml version="1.0" encoding="utf-8" ?>
<content>
<city>Los Angeles</city>
<state>CA</state>
</content>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
You actually don''t need to send XML at all. You could send your data
in a JSON format, and read it with responseText. Some of the more
recent versions of Prototype will actually eval it for you if you
pass it in an X-JSON header, or with the application/x-json content
header.
If you choose to continue using XML (and there are valid reasons for
doing so), you can use some of the same DOM methods you''d use in a
browser.
var cities = documentElement.getElementsByTagName(''city'');
var city = cities[0];
city.getAttribute(''id'');
documentElement.firstChild.firstChild.nextSibling;
etc.
Here''s a Google link to some pages on DOM methods:
http://www.google.com/search?q=javascript+DOM+methods
TAG
On Apr 18, 2007, at 9:08 PM, Andras Kende wrote:
>
> Hello,
>
> Can you give me a jumpstart how to parse the response xml file?
> I tried
>
> var ajax = new Ajax.Request(url,{method: ''get'',
parameters: params,
> onSuccess: handlerFunc, onFailure: reportError});
>
> var handlerFunc = function(t) {
> var xmlDoc = t.responseXML.documentElement;
>
> ????????????????????????????
>
> city = ?
> state = ?
>
> alert(city);
> }
>
>
>
>
>
> xml:
>
> <?php
> header("Content-Type: application/xml; charset=utf-8");
> ?>
> <?xml version="1.0" encoding="utf-8" ?>
> <content>
> <city>Los Angeles</city>
> <state>CA</state>
> </content>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
var text = this.getElementContent(nodes[i],''Name'');
getElementContent: function(element,tagName) {
/*--------- get XML element ---------*/
var childElement = element.getElementsByTagName(tagName)[0];
return childElement.text != undefined ? childElement.text :
childElement.textContent;
}
IE:text
firefox:textContent
《ajax in action》
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
And to make your life easier in C#, just take your nice XML file/stream/whatever, and feed it through this before returning it: http://www.phdcc.com/xml2json.htm -Jerod On 4/19/07, 周培公.C# <lanxmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > var text = this.getElementContent(nodes[i],''Name''); > > getElementContent: function(element,tagName) { > /*--------- get XML element ---------*/ > var childElement = element.getElementsByTagName(tagName)[0]; > return childElement.text != undefined ? childElement.text : > childElement.textContent; > } > IE:text > firefox:textContent > > 《ajax in action》 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks,your xml2json method very nice! But,in my codes,ajax class use data that c# websevice provide. How to convert XML to JSON in ajax? On 4月20日, 上午3时13分, "Jerod Venema" <jven...@gmail.com> wrote:> And to make your life easier in C#, just take your nice XML > file/stream/whatever, and feed it through this before returning it: > > http://www.phdcc.com/xml2json.htm > > -Jerod >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
http://www.thomasfrank.se/xml_to_json.html On 4/19/07, 周培公.C# <lanxmail@gmail.com> wrote:> > > Thanks,your xml2json method very nice! > But,in my codes,ajax class use data that c# websevice provide. > How to convert XML to JSON in ajax? > > On 4月20日, 上午3时13分, "Jerod Venema" <jven...@gmail.com> wrote: > > And to make your life easier in C#, just take your nice XML > > file/stream/whatever, and feed it through this before returning it: > > > > http://www.phdcc.com/xml2json.htm > > > > -Jerod > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs@googlegroups.com To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks,thanks,thank u very much! On 4月20日, 上午9时42分, "Jerod Venema" <jven...@gmail.com> wrote:> http://www.thomasfrank.se/xml_to_json.html > > On 4/19/07, 周培公.C# <lanxm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks,your xml2json method very nice! > > But,in my codes,ajax class use data that c# websevice provide. > > How to convert XML to JSON in ajax? > > > On 4月20日, 上午3时13分, "Jerod Venema" <jven...@gmail.com> wrote: > > > And to make your life easier in C#, just take your nice XML > > > file/stream/whatever, and feed it through this before returning it: > > > >http://www.phdcc.com/xml2json.htm > > > > -Jerod--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---