Lars
Lars

Reputation: 915

get text from Inputstream?

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();

Upvotes: 0

Views: 236

Answers (2)

Pete Houston
Pete Houston

Reputation: 15079

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/

Upvotes: 0

Marco Grassi
Marco Grassi

Reputation: 1202

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

Upvotes: 1

Related Questions