www.webdeveloper.com
Results 1 to 5 of 5

Thread: Dropdwon list in html

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Posts
    6

    Question 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>
    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>
    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 ?

  2. #2
    Join Date
    Mar 2014
    Posts
    6
    some pls help ..!!

  3. #3
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    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>
    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):

    PHP Code:
    $results $xml->xpath("//script[contains(script, 'sdnSTC')]");
    foreach(
    $results as $result) {
         
    // create the <option> tags 


  4. #4
    Join Date
    Mar 2014
    Location
    UAE
    Posts
    98
    Thanks for the help

  5. #5
    Join Date
    Mar 2014
    Posts
    6
    thank you for the help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles