SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    home
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Xml parser question

    Hi all !
    I have the next xml file:
    Code:
    <?xml version="1.0" encoding="ISO-8859-2"?>
    <structure>
    	<settings>
    		<name_test>test la ap</name_test>
    		<cat>AP</cat>
    		<teacher>Cucu Ionescu</teacher>
    		<start_data>2004-04-01</start_data>
    		<end_data>2004-05-01</end_data>	
    		<no_questions>2</no_questions>
    		<type_test>1</type_test>
    		<desc>some text</desc>
    	</settings>		
    	<elements>
            <question id="1" dificultate="1">
    			<text>question 1</text>
                        <controls>
                               <control tip="radio" name="q[1]" value="answer[1]">answer 1</control>
                               <control tip="radio" name="q[1]" value="answer[2]">answer 2</control>
                    	       <control tip="radio" name="q[1]" value="answer[3]">answer 3</control>
    						   <control tip="answer" name="answer[1]" value="2"></control>
                	    </controls>
    		</question>			
    <question id="2" dificultate="1">
    			<text>question 2</text>
                        <controls>
                               <control tip="radio" name="q[2]" value="answer[1]">answer 1</control>
                               <control tip="radio" name="q[2]" value="answer[2]">answer 2</control>
                    	       <control tip="radio" name="q[2]" value="answer[3]">answer 3</control>
    					   <control tip="answer" name="answer[2]" value="2"></control>
                	    </controls>
    		</question>			
    
    </elements>
    </structure>
    what i need to do is ti get the next output:
    /*settings output */
    PHP Code:
    $settings['name_test']="blah";
    $settings['cat']="AP";
    //.......

    /* elements otput */
    $elements[1]['text']="question 1";
    $elements[1]['dificultate']="1";
    $elements[1]['controls']['tip']="radio";
    $elements[1]['controls']['num_controls']=3;
    $elements[1]['controls']['control'][$control_number]['name']="q1";
    $elements[1]['controls']['control'][$control_number]['tip']="radio";
    $elements[1]['controls']['control'][$control_number]['value']="answer";
    $elements[1]['controls']['control'][$control_number]['text']="answer 1"
    and so on for the rest

    can someone help me with this.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you lookuped the PHP XML reference?

    http://www.php.net/manual/en/ref.xml.php

    It lists all the functoins of XML Parsing that is built into PHP if --xml is enabled and it may be useful to you.


Bookmarks

Posting Permissions

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