I am trying to remove the duplicate xml notes using jquery, can any one help?
My xml:
<Accounts>
<Account>
<Company>Company 1</Company>
<AccountNo>12345</AccountNo>
<CCY>EUR</CCY>
<Link>Link</Link>
<StatusIMG>Approved</StatusIMG>
</Account>
<Account>
<Company>Company 1</Company>
<AccountNo>12345</AccountNo>
<CCY>EUR</CCY>
<Link>Link</Link>
<StatusIMG>Approved</StatusIMG>
</Account>
<Account>
<Company>Company 1</Company>
<AccountNo>12345</AccountNo>
<CCY>EUR</CCY>
<Link>Link</Link>
<StatusIMG>Approved</StatusIMG>
</Account>
</Accounts>
JS:
$(document).ready(function () {
var LatestAccounturl = "scripts/jqwidgets/sampledata/latestAccountUpdates.xml";
var LatestAccountsource =
{
datatype: "xml",
mtype: 'GET',
datafields: [
{ name: 'Company', type: 'String'},
{ name: 'AccountNo', type: 'int' },
{ name: 'CCY', type: 'String' },
{ name: 'Link', type: 'bool' },
{ name: 'StatusIMG', type: 'String' }
],
root: "Accounts",
record: "Account",
url: LatestAccounturl
};
var xml = $(xml);
$('Accounts > Company', xml).each(function() {
alert($(this).text());
});
});
I want to check if the <company>
node having the same value (duplicated) then i need to remove the duplicated item, for this first step I am trying to get the xml node text value, which is not working in my alert:( any solution or better approach ?
The problem is the select:
Accounts > Company
tries to select direct children, but in the xml, Company is not a direct child ofAccounts
.correct would be
without the
>
, orwhich would be the preffered method, since
this
will hold the full account....now you can check for the company already existing and use$(this).remove()
to delete the node, in case its already present.