[BNM] help: parsing xml with jquery

Jason Bailey j.bailey at sussex.ac.uk
Wed Sep 24 16:11:15 BST 2008


Hello,

I'm using the jquery post function to return xml. It looks to be working 
OK. i.e. look at the page and stick in some variables then I see XML

i.e.
   header('Content-type: text/xml');  // php
   echo $xml; // I see XML

I'm trying to parse the xml using jquery but can't seem to get it to work. 
Pretty sure it's something stupid (me); can you see it? I'd just like to 
see the alert(stitle) popup working and go from there but I'm obviously 
missing something.

Jason.

The details....

Here's part of the JS (not using .ajax)

    		$.post("ajaxystuff.php", {title: this.value ,linkid:  123 }, 
function(xml) {
		      var out = $("title", xml).text();
			  $("#search-results").html(out);
			  var out='';
			  //alert(xml); // it's an xml document
			  $("data/record", xml).each( function(){  // not sure if this is working
				var stitle =$("title", this).text();       // wondering if it's 
variable scope?
				alert(stitle); // just trying to get this to work so far!
			  });
			  $("#search-results").html(out); // removed this bit for bnow

	
		    });


Here's a sample of the XML.
<data>
 <record>
   <title>title1</title>
   <apptype>P</apptype>
   <onlineflag/>
   <moa>wahoo1</moa>
   <prog_seq>14172</prog_seq>
   <qaf>wobble</qaf>
 </record>
 <record>
  <title>title2</title>
  <apptype>P</apptype>
  <onlineflag>Y</onlineflag>
  <moa>wahoo2</moa>
  <prog_seq>15840</prog_seq>
  <qaf>wibble</qaf>
 </record>
.....
</data> 


More information about the BNMlist mailing list. Powered by Wessex Networks