public static void printNode(NodeList nodeList, Document d)
{
for (int count = 0; count < nodeList.getLength(); count++)
{
Node tempNode = nodeList.item(count);
if (tempNode.getNodeType() == Node.ELEMENT_NODE)
{
if(tempNode.getChildNodes().getLength()==1)
{
if(tempNode.getNodeName()=="param-name")
{
tempNode = tempNode.getNextSibling();
System.out.println(tempNode.getTextContent());
}
}
else if (tempNode.getChildNodes().getLength() > 1)
{
printNode(tempNode.getChildNodes(),d);
}
else
{
print("ELSE")
}
}
}
}
我只是想從標籤從這個xml.file獲取文本值
<context-param>
<param-name>A</param-name>
<param-value>604800000</param-value>
</context-param>
<context-param>
<param-name>B</param-name>
<param-value>50</param-value>
</context-param>
<context-param>
<param-name>C</param-name>
<param-value>1</param-value>
</context-param>
訪問和獲取文本價值,但它不能正常工作,輸出 BLANKLINE _BLANKLINE_ BLANKLINE 。 。 。 。
那麼,有誰有想法?
非常感謝。
也許http://stackoverflow.com/questions/773012/getting-xml-node-text-value-with-java-dom?rq = 1可以幫助 – reporter 2013-04-26 08:47:14
不要使用'=='作爲st環比較。使用'equals()' – NilsH 2013-04-26 08:48:37
我建議將您的問題放在帖子的頂部,以便讀者在閱讀代碼之前瞭解上下文。 – 2013-04-26 09:03:45