You can use a XmlPullParser
class instance to achieve this.
public class UnboundItems {
private String name;
private String type;
// Whatever else you need...
public getName() { return name; }
public getType() { return type; }
public setName(String _name) { name = _name; }
public setType(String _type) { type = _type; }
}
private void parseXML(final XmlPullParser parser) throws XmlPullParserException, IOException {
int eventType;
ArrayList<UnboundItems> unbItems;
while ((eventType = parser.getEventType()) != XmlPullParser.END_DOCUMENT) {
UnboundItems currentUnboundItem; // For current iteration
boolean processing_unbound = false;
String curtag = null; // The current tag
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
curtag = parser.getName(); // Get the current tag's name
if (curtag.equals("xs:complexType"))
...
else if (curtag.equals("sequence")) { // The unbound items will be under this tag
currentUnboundItem = new UnboundItems();
processing_unbound = true;
}
else if ((curtag.equals("element")) && (processing_unbound)) {
// Get attribute values
final String name = parser.getAttributeValue(null, "name");
final String type = parser.getAttributeValue(null, "type");
currentUnboundItem.setName(name);
currentUnboundItem.setType(type);
...
}
}
break;
case XmlPullParser.END_TAG:
curtag = parser.getName();
if ((curtag.equals("xs:complexType")) && (processing_unbound)) {
// Probably add the UnboundItem to your array here
unbItems.add(currentUnboundItem);
...
processing_unbound = false;
}
break;
}
eventType = parser.next(); // Next event
}
}
As you may see, you can make it as complex as you need. This XML document is capable to be processed this way, so it's up to you how complex it is and your needs. Some useful links: