[問題] android無法使用getTextContent()
在取得xml後,要使用getTextContent()顯示內容,
卻發現android不支援使用getTextContent()?
但純java檔案卻可以使用。
網路上我去找了相關問題,看有沒有人解答。
有的是說用下列方式去取得
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
//String phone = fstNmElmnt.getTextContent();//原程式
String phone = fstNmElmnt.getFirstChild().getNodeValue();//新程式
System.out.println(phone);
但輸出之後,phone = null 。結論還是不行。
來源網址:
http://www.mail-archive.com/android-beginners@googlegroups.com/msg00854.html
-------
另一網址:http://zhidao.baidu.com/question/103141647.html
裡面的最佳答案是說,把getTextContent()用非抽象方法進行覆蓋重寫。
但他沒有附上getTextContent()
請問大家,有getTextContent()的函式可以提供給我嗎?
從早上找到現在還是找沒有,麻煩高手相助了>_<。謝謝。
修改成:
Document doc=null;
builder = factory.newDocumentBuilder();
doc = builder.parse(NetApi_4);
NodeList nl_4 = doc.getChildNodes();
Node employee = nl_4.item(i);
Text text=(Text) employee;
String s=text.getNodeValue();
System.out.println("s="+s);
(執行後↓)
Exception in thread "main" java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.dom.DeferredElementImpl
cannot be cast to org.w3c.dom.Text
at xml_split.main(xml_split.java:63)
--
自戀:26.42% 狗血:21.25% 愛:17.54%
超合金:11.85% 心中的翡翠森林:8.57% 燃燒的小宇宙:6.99%
渣渣:6.86% 反動思想:0.53%
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.171.66
→
03/10 16:35, , 1F
03/10 16:35, 1F
※ 編輯: terrybob 來自: 114.32.171.66 (03/10 18:43)
※ 編輯: terrybob 來自: 114.32.171.66 (03/10 19:58)