android - Jsoup - extract html from element -


i want extract html code div element using jsoup html parser library.

html code:

<div class="entry-content">    <div class="entry-body">       <p><strong>text 1</strong></p>       <p><strong> <a class="asset-img-link" href="http://example.com" style="display: inline;"><img alt="img_7519" class="asset  asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive" src="http://example.com" style="width: 500px;" title="img_7519" /></a><br /></strong></p>       <p><em>text 2</em> </p>    </div> </div> 

extract part:

string content = ... content of html above document doc = jsoup.parse(content); element el = doc.select("div.entry-body").first(); 

i want result el.html() whole html div tab entry-body:

<p><strong>text 1</strong></p>   <p><strong> <a class="asset-img-link" href="http://example.com" style="display: inline;"><img alt="img_7519" class="asset  asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive" src="http://example.com" style="width: 500px;" title="img_7519" /></a><br /></strong></p>   <p><em>text 2</em> </p> 

but first <p> tag:

<p><strong>text 1</strong></p> 

as mentioned in comments op, don't it. here reproduction of problem, , want:

string html = ""     +"<div class=\"entry-content\">"     +"   <div class=\"entry-body\">"     +"      <p><strong>text 1</strong></p>"     +"      <p><strong> <a class=\"asset-img-link\" href=\"http://example.com\" style=\"display: inline;\"><img alt=\"img_7519\" class=\"asset  asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive\" src=\"http://example.com\" style=\"width: 500px;\" title=\"img_7519\" /></a><br /></strong></p>"     +"      <p><em>text 2</em> </p>"     +"   </div>"     +"</div>"     ; document doc = jsoup.parse(html); element el = doc.select("div.entry-body").first(); system.out.println(el.html()); 

this results in following output:

<p><strong>text 1</strong></p>  <p><strong> <a class="asset-img-link" href="http://example.com" style="display: inline;"><img alt="img_7519" class="asset  asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive" src="http://example.com" style="width: 500px;" title="img_7519"></a><br></strong></p>  <p><em>text 2</em> </p> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -