这是我的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<frames>
<frame>
<name>FRAME-A</name>
<coordinatesA>
<x>75</x>
<y>75</y>
</coordinatesA>
<coordinatesB>
<x>75</x>
<y>490</y>
</coordinatesB>
<coordinatesC>
<x>645</x>
<y>75</y>
</coordinatesC>
<coordinatesD>
<x>1215</x>
<y>75</y>
</coordinatesD>
<coordinatesE>
<x>0</x>
<y>0</y>
</coordinatesE>
<image>@drawable/frameguideone</image>
</frame>
如何解析坐标中的标签 x 和 y BCDE 标签?我不知道该怎么做。任何人都可以帮我解决这个问题吗?我在谷歌中寻找它,但没有得到我的解决方案。
这是我的java解析:
public class XMLPullParserHandler {
List<Employee> frames;
private Employee frame;
private String text;
public XMLPullParserHandler() {
frames = new ArrayList<Employee>();
}
public List<Employee> getEmployees() {
return frames;
}
public List<Employee> parse(InputStream is) {
XmlPullParserFactory factory = null;
XmlPullParser parser = null;
try {
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
parser = factory.newPullParser();
parser.setInput(is, null);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String tagname = parser.getName();
switch (eventType) {
case XmlPullParser.START_TAG:
if (tagname.equalsIgnoreCase("frame")) {
// create a new instance of employee
frame = new Employee();
}
break;
case XmlPullParser.TEXT:
text = parser.getText();
break;
case XmlPullParser.END_TAG:
if (tagname.equalsIgnoreCase("frame")) {
// add employee object to list
frames.add(frame);
} else if (tagname.equalsIgnoreCase("name")) {
frame.setName(text);
} else if (tagname.equalsIgnoreCase("coordinates")) {
frame.setCoordinates(Integer.parseInt(text));
} else if (tagname.equalsIgnoreCase("image")) {
frame.setImage(text);
}else if(tagname.equalsIgnoreCase("x")){
frame.setX(Integer.parseInt(text));
}else if(tagname.equalsIgnoreCase("y")){
frame.setY(Integer.parseInt(text));
}
break;
default:
break;
}
eventType = parser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return frames;
}
}