0

The xml is available at 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();
    }

In above code I get node by attribute how can i get the child nodes of respective node. Also what is root node of this xml

Nauman Khalid
  • 331
  • 3
  • 10

1 Answers1

0

You have to iterate through the nodes like this:

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

Iterating so, you will get the child nodes. What do you mean by "Root Not". I did not get you

Priety
  • 308
  • 1
  • 4
  • 19