Re: [請益] 如何利用jsp抓取xml屬性的值

看板java作者 (淺水中)時間17年前 (2006/10/12 19:00), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《toughy (司庫寶寶)》之銘言: : <Face ID="1" Dependency_relation_type="3" Type="1"> : : : : : </Face> : 我想抓取 Dependency_relation_type 它的值(3) : 下面是我寫的程式碼 : Attr testAttribute = theParentElement.getAttributeNode("Dependency_relation_ty : int AttrNum; : AttrNum =Integer.parseInt(testAttribute.getNodeValue()); : ↑ : Tomcat出現了java.lang.NullPointerException : 對於這部分我是第一次去寫 找了很多書還是搞不懂原因 : 也不太知道該怎麼解決 : 懇請高手們稍微指點我一下迷津>"< : 謝謝~! 我不知道你是用那個API來處理一般的XML file 我習慣性是用dom4j 如果用dom4j的話大概就是這樣 假設你以經得到Face這個Element 如果要取他的Attribute Dependency_relation_type 只要 String var = face.AttributeValue("Dependency_relation_type"); 詳細資料你可以用google上搜尋dom4j -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.105.36
文章代碼(AID): #15BY1EmV (java)
文章代碼(AID): #15BY1EmV (java)