PDA

View Full Version : XML -> HTML parse // How to -> MySQL?



Wojtek
January 3rd, 2005, 14:39
XML Structure:


[...]
<recipe>
<recipename>Zucchini Dinner Rolls</recipename>
<serves>24</serves>
<keywords>Breads</keywords>
<ingredients>
<ingredient>
<quantity>1</quantity>
<unit>pkt</unit>
<name>quick-rise yeast</name>
</ingredient>
<ingredient>
<quantity>1</quantity>
<unit>cup</unit>
<name>warm water (120-130 degrees)</name>
</ingredient>
<ingredient>
<quantity>1/4</quantity>
<unit>cup</unit>
<name>butter or margarine softened</name>
</ingredient>
</ingredients>
<method>
Place zucchini in a bowl; sprinkle with 1/2 teaspoon bla bla bla
</method>
[...]


XML_Parser.php:


<?php
require("XMLConverter.class.php");

ob_start();
include("sample.xml");
$content=ob_get_contents();
ob_end_clean();

//Transform XML
$converter=new XMLConverter("taglib.tpl");
$content=$converter->parse($content);
$converter->destroyParser();

echo $content;

?>


REQUIRE ADDITIONNAL FILES ATTACHED AT BOTTOM OF THIS POST


The output is this: (XML_Parser.php)
http://www.cookingpages.com/cp/sample.php

Now, how would I modify all this so that each tag is seperated?
I want to transfer all those recipes into a MySql databse, but I need to break that down.

The last bit of XML_Parser.php:
echo $content;

I want to do this:

//DB Connect
Insert into DB ( recipename, servings, ingredients, method)

Any ideas how would I go to break this down?

Would I have to edit the function php files and add the database insert stuff there? I think so, however I'll need to make a bunch of IF's for each tag.
if recipename then insert into recipename
if ingredients insert into ingredients blablabla
not really effective no? Help :)


Thanks :wink2:

nag
January 10th, 2005, 01:11
i dont think that you have to put all the IF's for each tag , if your xml file contains the same format for each receipie it is not necessary try to look here

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

there are some good examples which be useful for you

basically you need to change the code in the function doParse() in the XMLConverter.class.php

Wojtek
January 10th, 2005, 09:53
mhale from WHT helped me with PEAR and its working wonderfully now :)

Case Closed