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()));
}
这样迭代,您将获得子节点。"不根"是什么意思。我没有得到你