android:我获取带有属性的节点如何获取其子节点
xml可在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的根节点是什么?您必须像这样迭代节点:
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()));
}