【问题标题】:android: I fetch node with attribute how can i get its child nodesandroid:我获取具有属性的节点我如何获取它的子节点
【发布时间】:2012-11-28 08:06:04
【问题描述】:

xml 位于http://thecybersoft.us/BridalExpo/Getmember.xml

    XPathFactory xpathfactory = XPathFactory.newInstance();
    XPath xpath = xpathfactory.newXPath();
    try {
         xpathexpression = xpath.compile("//@[name()='diffgr:id']");//bookstore//book
            result = xpathexpression.evaluate(doc,XPathConstants.NODESET);
           Log.v(result.toString(), "Value of result");
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

在上面的代码中,我按属性获取节点,如何获取各个节点的子节点。还有这个xml的根节点是什么

【问题讨论】:

    标签: android xml xml-parsing android-parser


    【解决方案1】:

    你必须像这样遍历节点:

       XPathFactory xpathfactory = XPathFactory.newInstance();
       XPath xpath = xpathfactory.newXPath();
        try 
               {
    
                        expr = xpath.compile("//@[name()='diffgr:id']");
            result = expr.evaluate(rootDoc, XPathConstants.NODESET);
            nodes = (NodeList) result;
            for (int i = 0; i < nodes.getLength(); i++)
    
                       {
           userDTO.setUser_id((int)Integer.parseInt(nodes.item(i).getTextContent()));
            }
    

    如此迭代,您将获得子节点。您所说的“根不”是什么意思。我没找到你

    【讨论】:

    • 它的根节点感谢您的回复。让我检查一下它是否适用于 android ;)
    猜你喜欢
    • 2012-06-05
    • 2013-05-29
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    相关资源
    最近更新 更多