First I would like to ask what is the format of the output of the Xpath query.
For me when I do the view source of my output I get view-source
actual output - output
Sample xml - xmlfile
My php code -
<?php
$variable=$_POST['module'];
$xmldoc = new DOMDocument();
$xmldoc->load('info.xml');
$xpathvar = new Domxpath($xmldoc);
$queryResult = $xpathvar->query("testcase[substring-after(
substring-after(script, '/'),
'/'
) = '$variable' or
substring-before(
substring-after(
substring-after(script, '/'),
'/'
),
'/'
) = '$variable']");
foreach($queryResult as $var)
{
echo $var->textContent;
echo "\n";
}
?>
What I want is to get the string ending with .tcl instead of full content
pls help !!
First you're looking only for a
testcase
element node, the actual path to the textcase nodes is/testcaseInfo/testcase
and can be optimized to any testcase element in the document://testcase
Next to validate if an element ends with a string you copy that part of the string and compare it.
//testcase[ substring( script, string-length(script) - string-length('.tcl') + 1 ) = '.tcl' ]
This will return the testcase element nodes, now you can use detail expression to fetch the data for each testcase:
Example:
Output: https://eval.in/120110