作者terrybob (罪云樵)
看板java
标题[问题] android无法使用getTextContent()
时间Wed Mar 10 15:18:54 2010
在取得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/[email protected]/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
1F:→ clubflymf:转Text text=(Text) node;String s=text.getNodeValue() 03/10 16:35
※ 编辑: terrybob 来自: 114.32.171.66 (03/10 18:43)
※ 编辑: terrybob 来自: 114.32.171.66 (03/10 19:58)