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:我获取带有属性的节点如何获取其子节点_Android_Xml_Xml Parsing_Android Parser - Fatal编程技术网

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

android:我获取带有属性的节点如何获取其子节点,android,xml,xml-parsing,android-parser,Android,Xml,Xml Parsing,Android Parser,xml可在 在上面的代码中,我按属性获取节点,如何获取各个节点的子节点。另外,这个xml的根节点是什么?您必须像这样迭代节点: XPathFactory xpathfactory = XPathFactory.newInstance(); XPath xpath = xpathfactory.newXPath(); try { expr = xpath.compile("//@[name()='diffgr:i

xml可在


在上面的代码中,我按属性获取节点,如何获取各个节点的子节点。另外,这个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()));
        }
XPathFactory XPathFactory=XPathFactory.newInstance();
XPath=xpathfactory.newXPath();
尝试
{
expr=xpath.compile(“/@[name()='diffgr:id']);
结果=expr.evaluate(rootDoc、XPathConstants.NODESET);
节点=(NodeList)结果;
对于(int i=0;i

如此迭代,您将得到子节点。您所说的“Root Not”是什么意思。我没有得到您的根节点

谢谢您的回复。让我检查一下它是否在android上工作;)
   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()));
        }