android:从xml文件获取数据
我想解析以下格式的xml字符串:android:从xml文件获取数据,android,xml,Android,Xml,我想解析以下格式的xml字符串: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?><account email="john@example.com"><contacts><contact><id>0</id><nickname></nickname><firstname></firstname><lastn
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><account email="john@example.com"><contacts><contact><id>0</id><nickname></nickname><firstname></firstname><lastname></lastname><emailxyz@gmail.com</email><passcode>p</passcode><creationdate>16 Dec 2013 17:40:58</creationdate><status>T</status></contact></contacts></account>
0xml文件基本上是一个字符串,因此您可以自己使用Scanner对象手动解析它,或者您可以解组器将其转换为对象并获取其数据字段NodeList accounts=getElementsByTagName(“account”);
NodeList accounts = getElementsByTagName("account");
for (int j = 0; j < accounts.getLength(); j++) {
accounts.item(j).getAttributes().getNamedItem("email");
}
对于(int j=0;j
NodeList nList=doc.getElementsByTagName(“账户”);
对于(int-temp=0;temp
NodeList accounts = getElementsByTagName("account");
for (int j = 0; j < accounts.getLength(); j++) {
accounts.item(j).getAttributes().getNamedItem("email");
}
NodeList nList = doc.getElementsByTagName("account");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("email id : " + eElement.getAttribute("email"));
}
}