I finally got it to work the way I want, here is what I was trying to accomplish. To all that provided answers, Thank you very much! I took pieces of each of your patterns, and customized it to what I need. I am by no means an android/java/xml expert, but here is what I got and its working the way I want yay!
public class MainActivity extends Activity {
Spinner spinner;
List<String> ingredient = new ArrayList<String>();
List<String> effect1 = new ArrayList<String>();
List<String> effect2 = new ArrayList<String>();
List<String> effect3 = new ArrayList<String>();
List<String> effect4 = new ArrayList<String>();
XmlResourceParser myXml;
int eventType;
String nodeValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadXml(); // Reads XML and loads it into Lists, One list for each element
convertListToSpinner(); // Takes Lists and merges data with Spinners (Currently Unimplemented)
}
private void convertListToSpinner() {
// TODO Auto-generated method stub
}
private void loadXml() {
// TODO Auto-generated method stub
myXml = getBaseContext().getResources().getXml(R.xml.xmlfilename);
try {
myXml.next();
eventType = myXml.getEventType(); // Get current xml Event
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(eventType != XmlPullParser.END_DOCUMENT){
if(eventType == XmlPullParser.START_DOCUMENT){
// checks can be placed here to make sure file is read
}
else if(eventType == XmlPullParser.START_TAG){
nodeValue = myXml.getName();
try{
if(nodeValue.equalsIgnoreCase("Ingredient")){ //Finds Ingredient tag
myXml.next(); //Since the ingredient tag does not hold the text, we go to next element area
ingredient.add(myXml.getText().trim()); // Set the text of the Ingredient tag to list
}
//Since the effect tags are followed by ending tags, we can just do nextText() to get tag text
if(nodeValue.equalsIgnoreCase("Effect1")){
effect1.add(myXml.nextText().trim()); // Set the text of the Effect1 tag to list
}
if(nodeValue.equalsIgnoreCase("Effect2")){
effect2.add(myXml.nextText().trim()); // ditto
}
if(nodeValue.equalsIgnoreCase("Effect3")){
effect3.add(myXml.nextText().trim()); // ditto
}
if(nodeValue.equalsIgnoreCase("Effect4")){
effect4.add(myXml.nextText().trim()); // ditto
}
}catch(Exception e){
e.getMessage();
}
}
try {
eventType = myXml.next();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i = 0; ingredient.size() > i; i++){
System.out.println(ingredient.get(i));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
And the XML file is in the current format.
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android" >
<item
name="item"
type="string">
<Ingredient>
Intrests
<effect1>
Android
</effect1>
<effect2>
Programming
</effect2>
<effect3>
Type O Negative
</effect3>
<effect4>
Sirenia
</effect4>
</Ingredient>
<Ingredient>
Virtues
<effect1>
Power
</effect1>
<effect2>
Money
</effect2>
<effect3>
Knowledge
</effect3>
<effect4>
Kindness
</effect4>
</Ingredient>
</item>
</resources>
I hope this helps others who are having similar problems. Again, thanks to Sobo and HADEV for contributing!!
I'm sure there is a much better way of doing what is being done, but I'm just happy I got this to work :)