Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

searching a value from a string

hi guys
I have strings like this

String xmlfileLocation  = "";
string xmldata =
"<strong>Id:</strong> 57A3<br />
<strong>Type:</strong> Buy<br />
<strong>Amount:</strong> $28<br />
 <a href="http://www.bamboo.com/instit/R_0117_3.xml">XML version</a>
 
From the above string xmldata i want to extract the url value of xml file
so my final output would be
String xmlfileLocation = "http://www.bamboo.com/instit/R_0117_3.xml";
Any idea whats the best way to acchieve this ?

Shiould i convert the xmldata string to an XML object first?

any help will be greatly appreciated
thanks
Avatar of Sumit Gupta
Sumit Gupta
Flag of France image

Hello,

Firstly it must be a well formed XML document. Meaning there be one root element defined and every tag is closed..

I don't know about Java. However, in PHP i would extract the value using the code snippet below :

$data ="<?xml version='1.0' encoding='utf-8'?>
    <root>
    <strong>Id:</strong><br>57A3</br>
    <strong>Type:</strong><br>Buy</br>
    <strong>Amount</strong><br>$28</br>
    <a href='http://www.bamboo.com/instit/R_0117_3.xml'>XML Versions</a>
</root>";
$xml = simplexml_load_string($data);
$children = $xml->xpath('/root/*');

foreach ($children as $test){
     if($test == "XML Versions"){
         $value = $test['href'];
         break;
     }
}  
echo 'The url under the link tag is'.$value;

The $value would essentially contain the url. Hope this helps!!!
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

that works, thanks doug