I'm trying to create an XML like this from a html form using php. I want to create complex element
<recipe>
<portion_size>
<portion_num>
</portion_num>
</portion_size>
<recipe_description>
<prep_time>
</prep_time
<recipe descrip>
</recipe descrip>
<recipe_description>
Something along the lines of that, however i cant seem to nest it properly using the DOM here is my php code. Does anyone have any advice?
$doc = new DOMDocument(); //open the object xml
$r = $doc->createElement("recipe");
$doc->appendChild($r);
$name = $doc->createElement('name',$name);
$r->appendChild($name);
$r = $doc->createElement("portion_size");
$doc->appendChild($r);
$child = $doc->createElement('portion_num',$portionNum);
$r->appendchild($child);
$prepTime = $doc->createElement('prep_time',$prepTime);
$r->appendChild($prepTime);
$recipeDescrip = $doc->createElement('descrip',$recipeDescrip);
$r->appendChild($recipeDescrip);
$utensilNum = $doc->createElement('utensil_num',$utensilNum);
$r->appendChild($utensilNum);
$utensilDescrip = $doc->createElement('utensil_descrip',$utensilDescrip);
$r->appendChild($utensilDescrip);
$quantityAmount = $doc->createElement('quantity_amount',$quantityAmount);
$r->appendChild($quantityAmount);
$ingredientName = $doc->createElement('ingredient_name',$ingredientName);
$r->appendChild($ingredientName);
$stepNum = $doc->createElement('step_num',$stepNum);
$r->appendChild($stepNum);
$stepDetail = $doc->createElement('step_detail',$stepDetail);
$r->appendChild($stepDetail);
$xml = "<recipe><foo><bar /></foo></recipe";and getting on with more important things.