Jay Roy
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that works, thanks doug
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>57
<strong>Type:</strong><br>
<strong>Amount</strong><br
<a href='http://www.bamboo.com/instit/R_0117_3.xml'>XML Versions</a>
</root>";
$xml = simplexml_load_string($dat
$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!!!