android:我获取带有属性的节点如何获取其子节点



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的根节点是什么

您必须像这样遍历节点:

   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()));
        }

这样迭代,您将获得子节点。"不根"是什么意思。我没有得到你

相关内容

  • 没有找到相关文章

最新更新