e.g。客户端:xmlpullparser提取"客户端:"成功,但我想取代"客户:"与" HELLO WORLD"并将其写入我刚读取的xml文件中。我该怎么做?
public static ArrayList<String> extract_xml (String path) throws XmlPullParserException, IOException {
ArrayList<String> xml_results = new ArrayList<String>();
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
InputStream open_xml = new FileInputStream(path);
xpp.setInput(open_xml, null);
int eventType = xpp.getEventType();
String currentTag = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
currentTag = xpp.getName();
} else if(eventType == XmlPullParser.TEXT) {
if("t".equals(currentTag) && xpp.getText().equals("Client: ")) {//tag to search for
xml_results.add(xpp.getText());
}
}
eventType = xpp.next();
}
return xml_results;
}
}