당신이 이것을 달성하기 위해 XmlPullParser
클래스의 인스턴스를 사용할 수 있습니다 : 당신이 다른 XML 파일과 함께 사용하면 마찬가지로로드 및 자바 maxOccurs="unbounded"
예와 요소를 검색하는 XPath를 사용하는 것이 좋습니다.
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
}
}
사용자가 볼 수 있듯이 필요한만큼 복잡하게 만들 수 있습니다. 이 XML 문서는 이러한 방식으로 처리 될 수 있기 때문에 얼마나 복잡한 지와 요구 사항을 사용자에게 달려 있습니다. 일부 유용한 링크 :
출처
2014-03-07 09:38:52
nKn
실제로 아파치의 ws xml 파서를 사용하는 이유는 모르지만 ... 나는 노력에 대한 현상금을 줄 것이다 ... – Hades