/    Sign up×
Community /Pin to ProfileBookmark

Dropdwon list in html

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>[/CODE]

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 ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pooja1110authorMar 13.2014 — some pls help ..!!
Copy linkTweet thisAlerts:
@Error404Mar 13.2014 — In your XML, there should be a root element, that is, an element that everything is contained within. It doesn't matter what you call it, for example, in the below code, <root> is the root element.

[CODE]
<root>
<testcase>
<status>1</status>
</testcase>
<testcase>
<status>2</status>
</testcase>
</root>
[/CODE]


To do what you want, I'd recommend using simple_xml's built-in xpath function, which allows you to easily retrieve elements and perform filtering operations. For example (UNTESTED):

[code=php]
$results = $xml->xpath("//script[contains(script, 'sdnSTC')]");
foreach($results as $result) {
// create the <option> tags
}
[/code]
Copy linkTweet thisAlerts:
@DigitalgardenMar 17.2014 — Thanks for the help ?
Copy linkTweet thisAlerts:
@pooja1110authorMar 26.2014 — thank you for the help ?
×

Success!

Help @pooja1110 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...