[英]Java - xml GetChildNodes IF and null value
我在使用xml時遇到兩個問題。
第一個問題:
此代碼正常工作。 如果參數只有一個孩子,則沒有孩子列表。
doc.getDocumentElement().getChildNodes().item(t).getLastChild().getNodeValue()
我想准備這樣的東西:
If(doc.getDocumentElement().getChildNodes().item(t).getLastChild().getNodeValue() !=null)
但這是行不通的,因為值永遠不會為空,但我需要類似的If can can check is value of list or not。
普通節點:
<name>Adam</name>
列表節點:
<car>
<tire>yes</tire>
<trunk>yes</trunk>
</car>
第二個問題:
如果我制作嵌套的ChildNode,我將無法實現價值,您知道哪里出了問題嗎?
節點示例:
<name>Adam</name>
如果我弄錯了,我會得到“名字”
doc.getDocumentElement().getChildNodes().item(t).getChildNodes().item(m).getNodeName()
如果我寫這個,我將為空,但我需要“ Adam”
doc.getDocumentElement().getChildNodes().item(t).getChildNodes().item(m).getNodeName()
答案-我應該使用ToLenght()> 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.