I’m having trouble accessing only one XML element that has the same name as other elements (i this case, the tag “name”). How do I access ONLY the “wantedName” below using jQuery?
<sample>
<input>
<value>0.2</value>
<name>varName</name>
</input>
<name>wantedName</name>
<output>
<value>4</value>
<name>varName2</name>
</output>
</sample>
Using $(xml).find(“name”) returns an array containing [varName, wantedName, varName2]. Unfortunately I can’t just resort to accessing the 1st index because the xml is dynamic, so I’m not sure at which index the “wantedName” will be.
I’d like to access “wantedName” by doing something like “if this has an immediate parent named <sample>, get it, otherwise ignore”.
Assuming the structure of the xml always looks like the example given (where name is directly after the input tag), I think this might work