这样的事情有助于开始
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
// return DOM
return doc;
之后你为此创建一个函数,然后你有你的文档
Document doc = parser.getDomElement(xml); // getting DOM element
然后你可以得到这样的元素,例如:
NodeList n1_item = doc.getElementsByTagName(KEY_ITEM_DESC);