[jQuery] Re: Parsing XML using jQuery

2008-07-12 Thread Diego A.
Hi there,

This plugin might be useful:

XML to JSON plugin v1.0
http://www.fyneworks.com/jquery/xml-to-json/

Cheers,
Diego A.

2008/7/9 Wallonman <[EMAIL PROTECTED]>:

>
> It seems that the DOM parsed 'on the fly' isn't ready for querying.
>
> When doing something weird like:
>
> var xml = $('Hello World!Bye World!');
> $(xml).appendTo("body");
>
> then the
>
> alert($("p").text());  // without context
>
> works !
>
>
>
>
>


-- 
Cheers,
Diego A.


[jQuery] Re: Parsing XML using jQuery

2008-07-09 Thread Wallonman

It seems that the DOM parsed 'on the fly' isn't ready for querying.

When doing something weird like:

var xml = $('Hello World!Bye World!');
$(xml).appendTo("body");

then the

alert($("p").text());  // without context

works !






[jQuery] Re: Parsing XML using jQuery

2008-07-09 Thread Alexandre Plennevaux

On Wed, Jul 9, 2008 at 12:38 PM, Wallonman <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Some hours that I don't understand why this basic Xml parsing with
> JQuery doesn't work:
>
>$(document).ready(function() {
>
>var xml = '>Hello World!';
>
>alert($("p", xml).text());
>
>});
>
> I get an empty string, instead of the expected Hello World!
>
> I had a look to a similar previous post
> http://groups.google.com/group/jquery-en/browse_thread/thread/fc60b77f884e6866/85cbd666774c6780)
> , but this didn't help me to get the revelation.
>
>



try alert($("p", xml).eq(0).text());
-- 
Alexandre Plennevaux
LAb[au]

http://www.lab-au.com


[jQuery] Re: Parsing XML using jQuery

2008-01-29 Thread Dave Stewart

Thanks David and Tim,
I didn't know that. Very useful.


[jQuery] Re: Parsing XML using jQuery

2008-01-29 Thread Timothee Groleau

On Mon, 2008-01-28 at 17:39 -0800, Dave Stewart wrote:
> Not sure if this is the best reply, but in order to access the
> structure, it has to be part of the DOM,

That is not correct. You can build a jQuery instance from a xml object
and use the various jQuery query options to search through the xml tree
directly.


Step, have you tried the method find?

$(xml).find('building').each(function()
{
alert($(this).find('city_id').text());
});

hth,
Tim.


[jQuery] Re: Parsing XML using jQuery

2008-01-28 Thread Alexandre Plennevaux
the first try will not work with latest jquery, as xpath is now into a
seperate plugin. So stick to your second try. Also, make sure you search
your xml when the xml is actually loaded, so in the ajax function callback

$.ajax({//your params here}, function(xml,status){
if(status=='success'){
$('building', xml).each(function()
   {
   alert($("city_id", this).text(););
   });
}
});

cheers,

alex

On Jan 29, 2008 7:29 AM, David Serduke <[EMAIL PROTECTED]> wrote:

>
> Actually if it doesn't have to be part of the DOM assuming you are
> passing in a context as the second parameter of $() which the original
> author is.
>
> I don't use the xpath plugin so I'm not sure about that but the second
> attempt you said failed worked for me.  I got 3 alert boxes with '1',
> '2', '3' just as I expected.  Here is my test case.
>
> http://www.w3.org/
> TR/html4/strict.dtd">
> 
>  
>Tester
>
>
>
>
>  function doIt() {
>$.get("jquery_xml_load.xml", function (xml) {
>  $("building", xml).each(function () {
>alert($("city_id", this).text());
>  });
>});
>  }
>
>  $(document).ready(function() {
>$("button").click(doIt);
>  });
>
>  
>  
>Do It
>  
> 
>
> The xml file is a copy and paste of what you put in your post.  I
> think your problem is somewhere other than what you posted.
>
> Hope that helps.
>
> David
>



-- 
Alexandre Plennevaux
LAb[au]

http://www.lab-au.com


[jQuery] Re: Parsing XML using jQuery

2008-01-28 Thread David Serduke

Actually if it doesn't have to be part of the DOM assuming you are
passing in a context as the second parameter of $() which the original
author is.

I don't use the xpath plugin so I'm not sure about that but the second
attempt you said failed worked for me.  I got 3 alert boxes with '1',
'2', '3' just as I expected.  Here is my test case.

http://www.w3.org/
TR/html4/strict.dtd">

  
Tester




  function doIt() {
$.get("jquery_xml_load.xml", function (xml) {
  $("building", xml).each(function () {
alert($("city_id", this).text());
  });
});
  }

  $(document).ready(function() {
$("button").click(doIt);
  });

  
  
Do It
  


The xml file is a copy and paste of what you put in your post.  I
think your problem is somewhere other than what you posted.

Hope that helps.

David


[jQuery] Re: Parsing XML using jQuery

2008-01-28 Thread Dave Stewart

Not sure if this is the best reply, but in order to access the
structure, it has to be part of the DOM, so best to inject in into a
placeholder first:

$('#placeholder).html(xml) // probably need to kill the xml
declaration first

Then you can use jQuery to traverse the tree.

:D