0
<media:thumbnail url="http:// mysite.com/wp-content/uploads/2013/11/mes1-300x186.png" width="320" length="125399" type="image/jpg"/>

How to extract the URL from this xml ? If I have the above as string ?

tony9099
  • 4,567
  • 9
  • 44
  • 73

2 Answers2

1

Supposing you have the XML string stored in String str, one lazy and simple way to retrieve the URL (if you always expect the same input text format) could be:

String url = str.split("\"")[1];
akrog
  • 326
  • 1
  • 10
1

Some times, as a quick "one time solution" you can use regular expressions.

String xml="<media:thumbnail url=\"http:// mysite.com/wp-content/uploads/2013/11/    mes1-300x186.png\" width=\"320\" length=\"125399\" type=\"image/jpg\"/>";
Pattern pattern=Pattern.compile("url\\s*=\\s*\\\"(.*?)\\\"");
Matcher m=pattern.matcher(xml);
if(m.find()){
   String urlValue=m.group(1);
   System.out.println(urlValue);
}
Dmitry
  • 127
  • 6