獲得節(jié)點值的兩種方法
不是很懂:
System.out.println(",節(jié)點值是:"+childNodes.item(k).getFirstChild().getNodeValue());
System.out.println(",節(jié)點值是:"+childNodes.item(k).getTextContent());
不是很懂:
System.out.println(",節(jié)點值是:"+childNodes.item(k).getFirstChild().getNodeValue());
System.out.println(",節(jié)點值是:"+childNodes.item(k).getTextContent());
2015-05-04
舉報
2015-05-04
以上是getNodeValue()方法的說明.
getTextContent()方法的說明比較長,我們用中文的:
(圖1)
(圖2)
總結(jié):
nodeValue如果為null或者只讀則該屬性設(shè)置無效.其返回值根據(jù)節(jié)點的類型不同返回也不同:具體請看圖1
getTextContent()返回的是當(dāng)前節(jié)點和當(dāng)前節(jié)點的后臺節(jié)點的文本內(nèi)容.