• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

XML -> HTML parse // How to -> MySQL?

Wojtek

W as in Whisky
NLC
XML Structure:
HTML:
[...]
  <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:
<?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:
 

Attachments

  • XMLConverter.class.php.txt
    6.9 KB · Views: 8
  • XMLParser.class.php.txt
    2.4 KB · Views: 5
  • taglib.tpl.txt
    803 bytes · Views: 6
Last edited:
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
 
Back
Top