I have the following XML
<ProjectResponse xmlns="Services.Messages" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Projects xmlns:a="Services.DTO">
<a:Project>
<a:ID>113</a:ID>
<a:Name>Test project</a:Name>
<a:Documents>
<a:ProjectDocument>
<a:FileName>DS.docx</a:FileName>
<a:ID>65</a:ID>
<a:ProjectID>113</a:ProjectID>
</a:ProjectDocument>
</a:Documents>
</a:Project>
</Projects>
</ProjectResponse>
When i perform $(this).find(‘[nodeName=a:ID]’) in ‘each’ function i get 2 IDs, one from Project and another from Document.
$(projectsXml).find('Projects').children().each(function() {
var projectId = $(this).find('[nodeName=a:ID]').text();
The question is how can i get only Project ID, not Document ID and another IDs that can occur ?
Use
.children()instead of.find()inside as well, so it only looks for immediate children, like this: