I need some help. I am a newbie to php ..
What I am trying to do is to parse an xml file and create a drop-down for the user.
I have attached how my drop down list looks currently.
What I want to do is to add a sub list to each option.. say to networkSecurity I want to add option a,b,c,d which I have to read from the same xml file.
How this can be done ?
To create normal drop-down list my code looks like
[CODE]<?php
$xml=simplexml_load_file(‘info.xml’);
foreach($xml->testcase as $var){
$var=explode(‘/’,$var->script);
$module[] =$var[2];
$testName[] = end($var);
}
echo “<pre>”;
print_r($module);
print_r($testName);
$modules = array_unique($module);
foreach($modules as $newarr)
{
$newmodules[]=$newarr;
}
print_r($newmodules);
?>
<select name=”module” id=”Module”>
<?php
$i=0;
foreach($newmodules as $mod)
{
?>
<option value=”<?php echo $mod;?>”><?php echo $newmodules[$i];?></option>
<?php
$i++;
}
?>
</select>
XML file –
[CODE]<testcase>
<name>AutoTFTP_IPv6_05.Enable_Disable</name>
<testcaseID>889437</testcaseID>
<testClass>WIRED</testClass>
<script>scripts/testSuite/hostAgentFeatures/fileTransfer/autoTftp/autoTftpIpv6/feature/ipv6AutoTftpEnable.tcl</script>
<testType>TCL</testType>
<origin>STC</origin>
<status>OK</status>
<qaCenterID>31265</qaCenterID>
<passThru>NULL</passThru>
<minProdVerAllowed>ALL</minProdVerAllowed>
<suiteInfo>
<suite>BASELINE</suite>
<suite>LEVEL3</suite>
</suiteInfo>
</testcase>
<testcase>
<name>Backup_Restore_04_Restore_mode_OFF_Restore</name>
<testcaseID>3630976</testcaseID>
<testClass>SDN_CONTROLLER</testClass>
<script>scripts/testSuite/sdnSTC/Flare/Backup_Restore/Sprint16_tests/Backup_Restore_RestoreModeOFFRestore.tcl</script>
<testType>TCL</testType>
<origin>STC</origin>
<status>OK</status>
<qaCenterID>89765</qaCenterID>
<passThru>NULL</passThru>
<minProdVerAllowed>ALL</minProdVerAllowed>
<suiteInfo>
<suite>SDN</suite>
<suite>SDN_CONTROLLER</suite>
</suiteInfo>
</testcase>[/CODE]
What i want to do is to parse the xml file, read the script tag and based on the 3rd position of script (hostAgentFeatures or sdnSTC) I have to create a dropdown list. Later I want to check all such script tags and read for 3rd position and for say sdnSTC I want to read the last value of script tag (ending with “.tcl”) and create it as a sub drop-down list for sdnSTC.
How this can be done ?