English 中文(简体)
• 如何在安康应用中使用DOM改为XML?
原标题:How to use DOM to read XML within Android applications correctly?

如果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();
        }
问题回答

http://developer.android.com/vis/org/xmlpull/v1/XmlPullParser.html#getAttributeCount%28%29”rel=“nofollow” iii 页: 1 MB-TAG

http://www.ibm.com/developerwork/opensource/library/x-android/“rel=“nofollow”>link。 在此,你还可以找到其他教区,如<条码>xmlPullParser。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签