从输入流获取文本?

发布于 2024-12-10 05:02:38 字数 2152 浏览 0 评论 0 原文

晚上好,

我想从输入流中获取一些文本,我从响应中检索这些文本:

InputStream inputStreamActivity = response.getEntity().getContent();  

XML 非常混乱,看起来像这样:

<div class="kpn-box width-272 boxwidth_onehalf height-154 boxheight_small  gradientfromtop-grey noSideBorders">     
<h2>Mijn beltegoed</h2>
<p class="contenttext"><div class="contentbox"><p>
   Beltegoed: € 1,00<br/>
   Verbruik deze maand: € 0,50<br/>
</p>
</div>
<div class="floatRight bottomlink-right"><a href="javascript:void('0');" id="panel3"  class="decorated-right kpn-bh-panel panel3" title="details" xml:lang="nl">details</a>
</div>
<div class="richpanel panel3" style="display:none;"><h2>Mijn beltegoed</h2>
<table cellpadding="0" cellspacing="0" class="personaltable"><tbody><tr class="alternativerow">
<td>Nieuw beltegoed:</td><td>€ 2,00</td></tr><tr class=""><td>Tegoed vorige periode:
<td>€ 1,0</td>
</td>
</tr>
<tr class="alternativerow">
<td>Tegoed tot 09-11-2011: 
<td>€5,00</td></td>
</tr>
<tr class=""><td/><td height="25px"/></tr>
<tr class="alternativerow">
<td>Verbruik sinds nieuw tegoed:</td>
<td>€ 0,49</td

执行此操作的最佳方法是什么? 我看到了一些 DocumentBuilder 的例子,但我不知道如何实现它。

一些示例代码会很好。

预先感谢您的帮助。

结果应该看起来像这样,我想将其放入标签中。

贝尔特戈德:1,00 欧元

Verbruik deze maand: € 0,50

Tegoed vorige periode:1,0 欧元

Tegoed tot 09-11-2011: €5,00

Verbruik sinds nieuw tegoed: € 0,49

编辑: 我决定为此使用 SAXParser,因为它似乎最适合移动设备。 谁能帮我一些示例代码? 谢谢..

我已经有了这个代码:

SAXParserFactory factory  = SAXParserFactory.newInstance(); 
SAXParser sp = factory.newSAXParser();             
XMLReader xr = sp.getXMLReader();             
                  
xr.parse(new InputSource(response.getEntity().getContent()));                                 
     
     
  response.getEntity().consumeContent();

Good evening,

I want to get some text from a inputstream which i retrieve from a response:

InputStream inputStreamActivity = response.getEntity().getContent();  

The XML is really messy and looks like this:

<div class="kpn-box width-272 boxwidth_onehalf height-154 boxheight_small  gradientfromtop-grey noSideBorders">     
<h2>Mijn beltegoed</h2>
<p class="contenttext"><div class="contentbox"><p>
   Beltegoed: € 1,00<br/>
   Verbruik deze maand: € 0,50<br/>
</p>
</div>
<div class="floatRight bottomlink-right"><a href="javascript:void('0');" id="panel3"  class="decorated-right kpn-bh-panel panel3" title="details" xml:lang="nl">details</a>
</div>
<div class="richpanel panel3" style="display:none;"><h2>Mijn beltegoed</h2>
<table cellpadding="0" cellspacing="0" class="personaltable"><tbody><tr class="alternativerow">
<td>Nieuw beltegoed:</td><td>€ 2,00</td></tr><tr class=""><td>Tegoed vorige periode:
<td>€ 1,0</td>
</td>
</tr>
<tr class="alternativerow">
<td>Tegoed tot 09-11-2011: 
<td>€5,00</td></td>
</tr>
<tr class=""><td/><td height="25px"/></tr>
<tr class="alternativerow">
<td>Verbruik sinds nieuw tegoed:</td>
<td>€ 0,49</td

What is the best way to do this?
I saw some examples with DocumentBuilder but i don not know how to get it implemented.

Some example code would be nice.

Thank you in advance for your help.

The outcome should look sometning like this, which i want to put in a label.

Beltegoed: € 1,00

Verbruik deze maand: € 0,50

Tegoed vorige periode: € 1,0

Tegoed tot 09-11-2011: €5,00

Verbruik sinds nieuw tegoed: € 0,49

Edit:
I decided to use the SAXParser for this, as it seemd the best for mobile devices.
Can anyone help me with some example code?
Thanks..

I already have this code:

SAXParserFactory factory  = SAXParserFactory.newInstance(); 
SAXParser sp = factory.newSAXParser();             
XMLReader xr = sp.getXMLReader();             
                  
xr.parse(new InputSource(response.getEntity().getContent()));                                 
     
     
  response.getEntity().consumeContent();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以往的大感动 2024-12-17 05:02:38

我建议你使用 Android 中的 xml 解析器之一。这是关于主要解析器的一个很好的示例/教程 http://www. Android 上的 ibm.com/developerworks/opensource/library/x-android/

I suggest you to use one of the xml parser in Android. Here it is a good example/tutorial on the main parsers http://www.ibm.com/developerworks/opensource/library/x-android/ on Android

酒与心事 2024-12-17 05:02:38

只需从该 HTML 源解析您需要的数据/内容即可。

您可以关注我的文章系列 Android XML Adventure - http://xjaphx.wordpress.com/2011/10/09/android-xml-adventure-what-is-the-thing- Called-xml/

Just parse data/content you need from that HTML source.

You can follow my article series Android XML Adventure - http://xjaphx.wordpress.com/2011/10/09/android-xml-adventure-what-is-the-thing-called-xml/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文