For my assignment I have to create a an e-learning xml file which will include course related information and then this xml should be saved in a mysql table.
Someone told me to create a table and put some of the xml tags as strings into the table fields. For example I have the main tag for this xml file 'course' which has 'unit' tag then I have 6 tags 'title, 'introduction, 'learningobjectives', 'section1', section2 and section3 which are children of unit.
So, I created a table called course which has 7 columns, unitid, unittitle, introduction, learningobjectives, section1, section2 and section3. I was told to just pick up each particular xml chunk and put it in the appropriate table field. So when i inserted data into the table I just put the xml code surrounded by single quotes and populated the table this way.
Now, in my PHP script, I connect to the database and try to retrieve each field. I know that I can use simplexml_load_string to parse the data but the problem is that the data being retrieved comes without the tags.
For example if my learningobjectives xml code which is saved in the learningobjectives column for unit1 has three children tags (obj1, obj2, obj3) and in my PHP script I retrieve that field as follows:
$query = "SELECT learningobjectives from course where unitid = 'unit1'"; $result = mysql_query( $query, $connection ); while ($row = mysql_fetch_array($result)){ echo $row["learningobjectives"]; }
It prints the objectives but without the xml tags. My question is what is the proper way of retrieving the whole chunk of xml as it was saved in the field so I can use simplexml_load_string and parse it as I need. Or Is there a better way to save the xml code into the database and retrieve it without putting the xml chunk into each field?
I really need help here. It will be greatly appreciated. Note: I tried to copy my xml code and include it with the question, but it did the same thing, the tags were skipped so I just put them in quotes instead of the triangle brackets.
This is urgent, I really need to complete this by tomorrow......Any suggestions will be greatly appreciated.enter code here
No comments:
Post a Comment