如果XML档案在当地储存在我的机器上,但当储存在电话线上时,我能得到我所需要的信息。
我曾尝试过XMLPullParser,但从中获取有关姓名的双向信息,我也像实际名称。
Code:
final String ANDROID_ID = "android:id";
try {
File fXmlFile = new File("res/layout/page1.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("Button");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
if (eElement.hasAttribute(ANDROID_ID))
System.out.println("ID: "
+ eElement.getAttribute(ANDROID_ID));
}
}
}
catch (Exception e) {
System.out.println("Catch");
e.printStackTrace();
}