Reputation: 1101
I'm parsing data from a json file. Now, I've a data like this
String Content = <p><img class="alignleft size-full wp-image-56999" alt="abdullah" src="http://www.some.com/wp-content/uploads/2013/12/imageName.jpg" width="348" height="239" />Text</p>
<p>Text</p> <p>Text</p><p>The post <a href="Some URL">Some Text</a> appeared first on <a href="http://www.some.com">Some Webiste</a></p>
Now, I want to divide this string in two pieces. I want to get this URL from src
.
http://www.some.com/wp-content/uploads/2013/12/imageName.jpg
and store it a variable. Also, I want to remove the last line The Post appeared...
and store the text's in another variable.
So, the questions are:
Upvotes: 0
Views: 78
Reputation: 12363
IN Java
Get a Document object
Document originalDoc = new SAXReader().read(new StringReader("<div>data</div>");
Then you can parse it.. (read this tutorial)
http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
In JavaScript to get attribute
var url = document.getElementsByTagName('img')[0].getAttribute('src');
In case if you have a string and you want a document object, use jquery
string stringValue = '<div>data</div>';
var myObject= $(stringValue);
Upvotes: 3
Reputation: 15418
String.substring(firstIndex, lastIndex)
to get the link from src
attributeJSoup
, will be useful in near futureUpvotes: 2
Reputation: 789
If its a well structured string you can parse it using any DOM parser and extract data from it...
Upvotes: 0