Click to See Complete Forum and Search --> : tag issue..Could be a javascript issue no sure..


joseph.gonzalez
08-11-2010, 09:41 AM
Hi, I am reading an xml file and it has several of the same tags.. So I am adding each of the strings to an array.. the problem occurs when I only have one tag Each character is placed into the array individually.. Example below..
Example 1;
<student>
<name>Josh</name>
<name>Joseph</name>
<name>Jacob</name>
</student>

Example 2;
<student>
<name>Josh</name>
</student>

code:
for (i = 0; i < student.name.length; i++) {
StudentArray.push(student.name[i]);

}

Example 1 Output: StudentArray[0]="Josh" [1]="Joseph"...and so on
Example 2 Output: StudentArray[0]="j" [1]="o"[2]="s"...

see.. When you only have one tag it counts the string length.. I want to avoid that and only count the tags.. Please No "parent-node"I would just like to work with the object itself as shown. thank you!

Charles
08-11-2010, 09:44 AM
names = student.getElementsByTagName ('name')