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 ?

2

2 Answers 2

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];
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.