I am trying to read data out of a XML file into an array with javascript.
My Xml file contains many groups structured as follows:
CODE
<group>
<groupName>The Real Friend</groupName>
<words>
<word>fantasy </word>
<word>violence </word>
<word>world-illusion </word>
<word>conspiracy </word>
<word>schizophrenia </word>
<word>childhood friends </word>
</words>
</group>
<groupName>The Real Friend</groupName>
<words>
<word>fantasy </word>
<word>violence </word>
<word>world-illusion </word>
<word>conspiracy </word>
<word>schizophrenia </word>
<word>childhood friends </word>
</words>
</group>
I want to get the groupName and then ONLY that group's words. I can get ALL the words and all the groups in the entire file by using
CODE
xmlDoc.getElementsByTagName("word").length
but then I don't know which words belong to which groups. The number of words for each group differ so I can't hard code that.I am looking for something in javascript that is similar to java's
CODE
XMLElement group = xml.getChild(i);
XMLElement words = group.getChild(1);
int numWords = words.getChildCount();
XMLElement words = group.getChild(1);
int numWords = words.getChildCount();
Any ideas?