Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android:从xml文件获取数据_Android_Xml - Fatal编程技术网

android:从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字符串:

 <?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"));
            }
    }