0

Hi all i have an xml file e.g

<?xml version="1.0"?> 
<recipes>
  <recipe>
     <rec_id>14</rec_id>
        <name>Spaghetti with Crab and Arugula</name>
        <overview>http://www</overview><time>2010-11-11 14:35:11</time>                           <image>localhost/pics/SpaghettiWithCrabAndArugula.jpg</image>
        <instructions>
          <instruction>
             <instruction_id>14</instruction_id>
             <instruction_text>Cook spaghetti according to directions on package. Drain            and set aside.</instruction_text>
             </instruction>
          <instruction>
              <instruction_id>15</instruction_id>
              <instruction_text>In a large saucepan, heat olive oil. Add garlic and chili and saute for 30 seconds. Stir in crabmeat and lemon juice. Season with salt and pepper.  Cook for 3-5 minutes, stirring constantly. Add arugula leaves.</instruction_text>                                    </instruction>
           <instruction>
              <instruction_id>16</instruction_id>
              <instruction_text>Add pasta and toss to coat. Adjust taste with salt and pepper if necessary. Serve immediately.</instruction_text>
           </instruction>
         </instructions>
         <ingredients>
           <ingredient>
              <ingredient_id>7</ingredient_id>
              <ingredient_name>13 ounces spaghetti</ingredient_name>
              <ammount>10</ammount>
           </ingredient>
         <ingredient>
              <ingredient_id>8</ingredient_id>
              <ingredient_name>1 pound crabmeat</ingredient_name>
              <ammount>10</ammount>
          </ingredient>
             <ingredient>
                <ingredient_id>9</ingredient_id>
                <ingredient_name>7 ounces arugula, washed</ingredient_name>                  <ammount>10</ammount>
               </ingredient> 
                <ingredient>
                   <ingredient_id>10</ingredient_id>
                   <ingredient_name>2 cloves garlic, finely chopped</ingredient_name>                    <ammount>10</ammount>
                 </ingredient>
                 <ingredient>
                   <ingredient_id>11</ingredient_id>
                   <ingredient_name>1 chili pepper, seeded and finely chopped</ingredient_name>
                   <ammount>10</ammount>
                  </ingredient>
              <ingredient>
                 <ingredient_id>12</ingredient_id>
                     <ingredient_name>4 tablespoons lemon juice</ingredient_name>

                         <ammount>10</ammount></ingredient><ingredient>                <ingredient_id>13</ingredient_id>
                         <ingredient_name>6 tablespoons olive oil</ingredient_name>                    <ammount>10</ammount>
</ingredient>
             <ingredient>
               <ingredient_id>14</ingredient_id>
               <ingredient_name>Salt and pepper to taste</ingredient_name>   <ammount>10</ammount>
                </ingredient>
            </ingredients>
         </recipe>

<recipe><rec_id>15</rec_id><name>stew recipe </name><overview>http://www</overview><time>2010-11-11 14:42:09</time><image>localhost/pics/stew2.jpg</image><instructions><instruction><instruction_id>17</instruction_id><instruction_text>Coat the steak with the flour, keeping any leftover flour.</instruction_text></instruction><instruction><instruction_id>18</instruction_id><instruction_text>Heat the vegetable oil in a large pot.</instruction_text></instruction><instruction><instruction_id>19</instruction_id><instruction_text>Add the steak and cook until brown then remove the steak and reduce the heat.</instruction_text></instruction><instruction><instruction_id>20</instruction_id><instruction_text>Add the onion and slowly cook until the onion is tender. Add the remaining flour.</instruction_text></instruction><instruction><instruction_id>21</instruction_id><instruction_text>Slowly stir in the stock, add the Worcestershire sauce, salt and pepper and continue to cook, stirring until all the ingredients in the pot are blended together and the mixture gets thicker.</instruction_text></instruction><instruction><instruction_id>22</instruction_id><instruction_text>Put the steak back into the pot, reduce the heat and simmer for about two and a half hours.</instruction_text></instruction><instruction><instruction_id>23</instruction_id><instruction_text>Add the vegetables, stirring well and bring back to the boil. Reduce the heat, cover and simmer for about 30 minutes or until the steak and vegetables are lovely and tender.</instruction_text></instruction></instructions><ingredients><ingredient><ingredient_id>15</ingredient_id><ingredient_name>1kg stewing steak cut into cubes</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>16</ingredient_id><ingredient_name>1 chopped onion  1000ml stock</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>17</ingredient_id><ingredient_name>700g potatoes cut into chunks</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>18</ingredient_id><ingredient_name>25g plain flour</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>19</ingredient_id><ingredient_name>75ml vegetable oil</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>20</ingredient_id><ingredient_name>1 teaspoon of Worcestershire sauce</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>21</ingredient_id><ingredient_name>salt and pepper</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>22</ingredient_id><ingredient_name>450g carrots cut into chunks</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>23</ingredient_id><ingredient_name>2 leeks cut into chunks</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>24</ingredient_id><ingredient_name>1 swede cut into cubes</ingredient_name><ammount>11</ammount></ingredient><ingredient><ingredient_id>25</ingredient_id><ingredient_name>3 parsnips cut into cubes</ingredient_name><ammount>11</ammount></ingredient></ingredients></recipe></recipes>

and my php code is

$url = "cafe.xml";
// get xml file contents
$xml = simplexml_load_file($url);

// loop begins
foreach($xml->recipe as $recipe)
{

echo "<p>";

echo "<strong>Recipe Id:</strong> ".$recipe->rec_id."<br/>";

echo "<strong>Name:</strong> ".$recipe->name."<br/>";

echo "<strong>Overview:</strong> ".$recipe->overview."<br/>";

echo "<strong>Time:</strong> ".$recipe->time."<br/>";

echo "<strong>Image:</strong> ".$recipe->image."<br/>";



foreach($recipe->instructions->instruction as $instruction) {
         echo "<strong>Instruction text:</strong> ". $instruction->text."<br />";
    }
echo "</p>";

}

my question is how can i retrieve all the instructions and ingredients
its only retrieve the recipe part e.g
rec_id
name
overview
time
image

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.