Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery finding element by attibute value
    primarykey
    data
    text
    <p>I have a xml file and would like to retrieve the contents of the key attribute. </p> <p>The structure of the xml file is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt; &lt;MPL Version="2.0" Title="MCWS - Files - 2100"&gt; &lt;Item&gt; &lt;Field Name="Key"&gt;1383&lt;/Field&gt; &lt;Field Name="Name"&gt;En la Planta de Tus Pies&lt;/Field&gt; &lt;Field Name="Artist"&gt;Alejandro Sanz&lt;/Field&gt; &lt;Field Name="Album"&gt;El Tren de los Momentos&lt;/Field&gt; &lt;Field Name="Genre"&gt;Latin&lt;/Field&gt; &lt;/item&gt; &lt;Item&gt; &lt;Field Name="Key"&gt;938&lt;/Field&gt; &lt;Field Name="Name"&gt;Something Beautiful&lt;/Field&gt; &lt;Field Name="Artist"&gt;Robbie Williams&lt;/Field&gt; &lt;Field Name="Album"&gt;Escapology&lt;/Field&gt; &lt;Field Name="Genre"&gt;Rock&lt;/Field&gt; &lt;/item&gt; &lt;/MPL&gt; </code></pre> <p>My JQuery function looks like this:</p> <pre><code>function displaySongs() { $.ajax({ type: "GET", url:"Files.xml", dataType: "xml", success: function(xml){ var content = ""; $(xml).find('Item').each(function(){ var songId = $(this).find('Field[Name="Key"]'); var songName = $(this).find('Field[Name="Name"]'); content += "&lt;div class=\"Song\"&gt;" + songName.text() + "&lt;/div&gt;"; $("#output").html(content); }); }, error: function() { alert("An error occurred while processing XML file."); } }); } </code></pre> <p>My problem is that i am not finding the content of the Name="Name" node, but get the entire item result. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload