Not sure if this is an XML question or a JQuery question but I have an XML file which is given to me by another company (so I cannot make any changes to its structure). The general format is:
<products>
<product>
<name>Title</name>
<description>Description ...</description>
<field>
<name>fieldname</name>
<value>New</value>
</field>
</product>
....
</products>
The following jquery code loops through the XML and should print out just the product name. Unfortunately the name filed in <field> is also printed out.
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "pf.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml)
{
//find every product and print the name
$(xml).find("product").each(function()
{
$("#output").append($(this).find("name").text() + "<br />");
});
}
can I make this code only refer to the actual product name ?
<products>
<product>
<name>Title</name>
<description>Description ...</description>
<field>
<name>fieldname</name>
<value>New</value>
</field>
</product>
....
</products>
The following jquery code loops through the XML and should print out just the product name. Unfortunately the name filed in <field> is also printed out.
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "pf.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml)
{
//find every product and print the name
$(xml).find("product").each(function()
{
$("#output").append($(this).find("name").text() + "<br />");
});
}
can I make this code only refer to the actual product name ?