2012-11-28 41 views
0

的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

回答

0

你有過這樣的節點進行迭代的根節點:

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

迭代的話,你會得到的子節點。 「Root Not」是什麼意思?我沒有得到你

+0

它的根節點感謝你的回覆。讓我檢查一下它是否適用於android;) –

相關問題