-2

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 :(

Newbie
  • 9
  • 5

2 Answers2

0

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
Scuzzy
  • 12,186
  • 1
  • 46
  • 46
  • no i tried this and it gives me error :- `Notice: Undefined property: DOMElement::$script in C:\wamp\www\test.php on line 23` – Newbie Mar 18 '14 at 05:06
  • Please review my edit, sorry I made the mistake of assuming SimpleXML – Scuzzy Mar 18 '14 at 05:09
  • hey can you guide me about how can i just get the string ending with ".tcl" instead of full script tag ? – Newbie Mar 18 '14 at 05:14
  • `echo basename($var->getElementsByTagName('script')->item(0)->textContent);` – Scuzzy Mar 18 '14 at 05:16
  • btw y are you asking me to change `$queryResult = $xpathvar->query("//testcase` – Newbie Mar 18 '14 at 05:18
  • Yes, starting your xpath with `//testcase` means it will find any `` in the XML document. Otherwise you could simply build a path from root such as `/testcaseInfo/testcase/`. Also I recommend using http://www.php.net/manual/en/simplexmlelement.xpath.php – Scuzzy Mar 18 '14 at 05:30
0

to have the output in the array you can do -

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

Learning
  • 198
  • 1
  • 11