Re: [請益] 如何利用jsp抓取xml屬性的值
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):