Results 1 to 7 of 7

Thread: Need help in php reading xml

  1. #1
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question Need help in php reading xml

    Hi i have a career2.xml which has only following content..

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    <f1>Tove</f1>
    <f2>Jani</f2>
    <f3>Reminder</f3>
    </note>

    Can anyone tell me how to load these three tags into three different variables in php..
    Like $f1, $f2, $f3 . And the value of
    $f1 must be Tove, $f2 must be jani, $f3 must be reminder.
    Please help me .. its urgent... Thank you....

  2. #2
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    I just tried to figure this one out, which did not work at all...I'm very interested in how this works myself.

  3. The Following User Says Thank You to I am Abby For This Useful Post:

    naveen.brite (04-29-2010)

  4. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

  5. The Following User Says Thank You to traq For This Useful Post:

    naveen.brite (04-29-2010)

  6. #4
    Join Date
    Apr 2010
    Location
    University of Illinois
    Posts
    86
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by traq View Post
    urgent, huh? homework?
    simpleXML
    oh.
    So naveen.brite, when you figure it out please post it.

    We have already been taught to read:

    $file = 'career2.xml';
    $xml = simplexml_load_file($file);

    foreach($xml->children() as $note){
    echo '
    <hr>
    f1: '.$note->f1.'<br />
    f2: '.$note->f2.'<br />
    f3: '.$note->f3.;
    }

    So you just need to change that from reading to storing without overwriting.
    So you would need a varible $count

  7. The Following User Says Thank You to I am Abby For This Useful Post:

    naveen.brite (04-29-2010)

  8. #5
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Smile

    I have tested the below code and it works fine.
    <?php
    $file = 'career2.xml';
    $xml = simplexml_load_file($file);
    $x = $xml->children();
    print 'f1: '.$x->f1.'<br>';
    print 'f2: '.$x->f2.'<br>';
    print 'f3: '.$x->f3.'<br>';
    ?>

  9. The Following User Says Thank You to katierosy For This Useful Post:

    naveen.brite (04-29-2010)

  10. #6
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Hi friends,
    finally the simple solution for my need... thanks to katierosy ....
    hi Abby.. the katierosy's code works...
    And never forget Traq. his link is really useful for further advancement...

  11. #7
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question

    Hi,
    Now its getting tougher... i don't understand how to fetch the values from a xml which has various tags... I need only the options of the three tags namely with name function area(line 76), role(line 92), experience(line 110).... to be fetched in php...

    the xml is
    Code:
    <?xml version="1.0"?>
    <tabset>
    	<images>
    		<item src="resources/blue-back.jpg" id="blueBack"/>
    		<item src="resources/map.gif" id="map"/>
    		<item src="resources/career-back.jpg" id="careers"/>
    		<item src="resources/poll-back.jpg" id="poll"/>
    		<item src="resources/poll-bluebar.jpg" id="pollBlueBar" />
    		<item src="resources/poll-greenbar.jpg" id="pollGreenBar" />
    		<item src="resources/poll-sidebar.jpg" id="pollSidebar" />
    	</images>
    	<image_reader>getImage.php</image_reader>
    	<tab>
    		<title>Tweets</title>
    		<type>HotSpots</type>
    		<content>
    			<line1>The latest from</line1>
    			<line2>Citrix Worldwide</line2>
    			<map>map</map>
    			<background>blueBack</background>
    			<twitter>
    				<source>twitter.php</source>
    				<user>
    					<name>CitrixBlogs</name>
    					<location x="128" y="134"/>
    				</user>
    				<user>
    					<name>simplyserve</name>
    					<location x="350" y="115"/>
    				</user>
    				<user>
    					<name>CitrixKCForums</name>
    					<location x="490" y="170"/>
    				</user>
    				<user>
    					<name>harrylabana</name>
    					<location x="50" y="100"/>
    				</user>
    				<user>
    					<name>JMaynard_Citrix</name>
    					<location x="585" y="265"/>
    				</user>
    				<user>
    					<name>Vinnysosa</name>
    					<location x="300" y="100"/>
    				</user>
    				<user>
    					<name>SitRightOnCloud</name>
    					<location x="350" y="54"/>
    				</user>
    				<user>
    					<name>CitrixReady</name>
    					<location x="610" y="118"/>
    				</user>
    			</twitter>
    		</content>
    	</tab>
    	<tab>
    		<title>Video</title>
    		<type>video</type>
    		<content>
    			<background>#000000</background>
    			<title>Apple to Zappo</title>
    			<sub>Stories from Citrix everywhere…</sub>
    			<video>resources/apple-zappo.flv</video>
    		</content>
    	</tab>
    	<tab>
    		<title>Careers</title>
    		<type>form</type>
    		<content>
    			<background>careers</background>
    			<form src="form.php" method="POST" />
    			<careers>
    				<section>
    					<name>Functional Area</name>
    					<slug>func</slug>
    					<options>
    						<item id="1" name="All" />
    						<item id="2" name="Application Programming" />
    						<item id="3" name="Database" />
    						<item id="4" name="Client Server" />
    						<item id="5" name="E-Commerce, Internet Tech" />
    						<item id="6" name="Mobile" />
    						<item id="7" name="Networking" />
    						<item id="8" name="Security" />
    						<item id="9" name="QA & Testing" />
    						<item id="10" name="Other" />
    					</options>
    				</section>
    				<section>
    					<name>Role</name>
    					<slug>role</slug>
    					<options>
    						<item id="1" name="All" />
    						<item id="2" name="QA Engineer" />
    						<item id="3" name="Build Engineer" />
    						<item id="4" name="Software Test Engineer" />
    						<item id="5" name="Network Administration" />
    						<item id="6" name="Web Application Engineer" />
    						<item id="7" name="Data Architect" />
    						<item id="8" name="Database Administrator" />
    						<item id="9" name="Integration Engineer" />
    						<item id="10" name="Dev Manager" />
    						<item id="11" name="Dev Engineer" />
    						<item id="12" name="Other" />
    					</options>
    				</section>
    				<section>
    					<name>Experience</name>
    					<slug>exp</slug>
    					<options>
    						<item id="1" name="0 years" />
    						<item id="2" name="1-3 years" />
    						<item id="3" name="3-5 years" />
    						<item id="4" name="5-7 years" />
    						<item id="5" name="7-10 years" />
    						<item id="6" name="Over 10 years" />
    					</options>
    				</section>
    			</careers>
    		</content>
    	</tab>
    	<tab>
    		<title>Knowledge Poll</title>
    		<type>quiz</type>
    		<content>
    			<background>poll</background>
    			<text_labels>
    				<intro_head>How good are you really?</intro_head>
    				<intro_body>Take this quiz & find out</intro_body>
    				<intro_width>195</intro_width>
    				<question>Question #:</question>
    				<correct>Excellent! That's right.</correct>
    				<wrong>Oops! You got it wrong.</wrong>
    				<perc_correct>got this answer right</perc_correct>
    				<perc_wrong>got this answer wrong</perc_wrong>
    			</text_labels>
    			<poll>
    				<submit src="answer.php" method="POST"/>
    				<questions>
    					<item>
    						<id>23</id>
    						<question>All VDIs (Virtual Desktop Infrastructure) are made equal?</question>
    						<options>
    							<item name="True" />
    							<item name="False" correct="true"/>
    						</options>
    						<explanation>
    							<![CDATA[Unlike other VDI only offerings, which only address a narrow set of use cases, Citrix XenDesktop® delivers Windows desktops as an On-Demand service to any user, anywhere using FlexCast™ delivery technology.]]>
    						</explanation>
    						<correct_perc>0.7</correct_perc>
    					</item>
    					<item>
    						<id>24</id>
    						<question>Who's the man?</question>
    						<options>
    							<item name="Ridley Scott" />
    							<item name="Quentin Tarantino" correct="true"/>
    							<item name="Michael Bay" />
    							<item name="Steven Speilberg" />
    						</options>
    						<explanation>
    							<![CDATA[Without question, undoubtedly from the moment he made Resovoir Dogs to the end of time, Tarantino has been, and always will be: The Man.]]>
    						</explanation>
    						<correct_perc>0.85</correct_perc>
    					</item>
    				</questions>
    			</poll>
    		</content>
    	</tab>
    </tabset>
    The final idea is to get the option values of the said three tags from the xml and display it as an option values in select inputbox in a form....
    Can somebody lend me atleast a clue... And its not homework...
    Last edited by naveen.brite; 04-30-2010 at 12:58 PM.

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
  •