javascript - Find an XML Node Using jQuery And Use Its Values -


i'm using xml file this:

<test>     <unit>         <title>test 1</title>         <date>01/07/2011</date>         <content format="html"><![cdata[here goes content]]></content>     </unit>      <unit>         <title>testing new xml</title>         <date>27/06/2011</date>         <content format="html"><![cdata[here goes content]]></content>     </unit>     <!-- lot of stuff --> </test> 

i want use jquery search on xml document <title> given , entire <unit>, can work values this:

function append(title, date, content) {     $("#unit").append("<h1 id='title'><b>" + title + "</b></h1><h2 id='date'>" + date + "</h2><p>" + content + "</p>"); } 

how can this?

ps: i've been using this base of xml reading

is you're looking for? click here (jsfiddle link)

in code you'll have xml , store in variable first did. code may not you're looking may starting point. play code , let me know if you're looking or not.

you try (same code jsfiddle link using alerts instead of appending data dom)

var xml = "<test><unit><title>test 1</title><date>01/07/2011</date><content format='html'>some content here</content></unit><unit><title>testing new xml</title><date>27/06/2011</date><content format='html'>some more content here</content></unit></test>";  $(xml).find("unit").each(function(){     if($(this).find("title").length > 0){         var unitdata = $(this).text();         alert(unitdata);     } }); 

that should give 2 alerts.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -