Question

I have the output of my xpath query like by using phhp 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";

        }

?>

output -

Backup_Restore_04_Restore_mode_OFF_Restore 3630976 SDN_CONTROLLER scripts/testSuite/sdnSTC/Flare/Backup_Restore/Sprint16_tests/Backup_Restore_RestoreModeOFFRestore.tcl This test case is to verify Message on Restore mode OFF TCL STC OK 89765 NULL ALL SDN SDN_CONTROLLER target:system:family:stc-auto-workstation-B Backup_restore_05_restore_mode_on_No_Restore_file 3631050 SDN_CONTROLLER scripts/testSuite/sdnSTC/Flare/Backup_Restore/Sprint16_tests/Backup_Restore_RestoreModeOnNORestoreFile.tcl To verify Restore mode ON and there is no backupfile available for Restore and restart flare in normal mode TCL STC OK 89766 NULL ALL SDN SDN_CONTROLLER target:system:family:stc-auto-workstation-B 

what i want is to get all the string ending with .tcl from this output.

How this can be done. Pls help.. m stuck here since last 1 week :(

Was it helpful?

Solution

to have the output in the array you can do -

foreach($queryResult as $var) { $array[] = basename($var->getElementsByTagName('script')->item(0)->textContent); }

OTHER TIPS

Try this approach

foreach($queryResult as $var)
{
  echo $var->getElementsByTagName('script')->item(0)->textContent;
  echo "\n";
}

Please change

$queryResult = $xpathvar->query("testcase

to

$queryResult = $xpathvar->query("//testcase
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top