I'm looking at the PHP xml processing instructions.
I'm hosting at lycos, so using PHP4.1 with dom enabled.
I have downloaded (and uploaded!) the 'recipe' example from phpbuilder
article.
However, I cannot get any ->content to display.
I've left myself with just the barest of test apps. Cannot get it working.
A web trawl indicates that I'm doing the right thing (or I'm just totally
misunderstanding this whole process).
Any help appreciated, code follows;
The 'error' is that the ->content always returns an empty string....
======= XML ========
<?xml version="1.0"?>
<recipe>
<name>Chicken Tikka</name>
<author>Anonymous</author>
<date>1 June 1999</date>
<ingredients>
<item>
<desc>Boneless chicken breasts</desc>
<quantity>2</quantity>
</item>
<item>
<desc>Chopped onions</desc>
<quantity>2</quantity>
</item>
<item>
<desc>Ginger</desc>
<quantity>1 tsp</quantity>
</item>
<item>
<desc>Garlic</desc>
<quantity>1 tsp</quantity>
</item>
<item>
<desc>Red chili powder</desc>
<quantity>1 tsp</quantity>
</item>
<item>
<desc>Coriander seeds</desc>
<quantity>1 tsp</quantity>
</item>
<item>
<desc>Lime juice</desc>
<quantity>2 tbsp</quantity>
</item>
<item>
<desc>Butter</desc>
<quantity>1 tbsp</quantity>
</item>
</ingredients>
<servings>
3
</servings>
<process>
<step>Cut chicken into cubes, wash and apply lime juice and salt</step>
<step>Add ginger, garlic, chili, coriander and lime juice in a separate
bowl</step>
<step>Mix well, and add chicken to marinate for 3-4 hours</step>
<step>Place chicken pieces on skewers and barbeque</step>
<step>Remove, apply butter, and barbeque again until meat is tender</step>
<step>Garnish with lemon and chopped onions</step>
</process>
</recipe>
======= XML ========
======= PHP ========
<html>
<head>
</head>
<body bgcolor="white">
<hr>
<?
// data file
$file = "recipe.xml";
// create a document object
print("<br>DBG: calling xmldocfile($file)</br>");
$dom = xmldocfile($file);
print("<br>DBG: xmldocfile returns ($dom)</br>");
// get reference to root node
$root = $dom->root();
print( "<br>DBG: RootNode=" . $root->tagname . "</br>" );
print_r( $root );
// get children
$children = $root->children();
// run a recursive function starting here
printData($children);
// this function accepts an array of nodes as argument,
// iterates through it and prints HTML markup for each tag it finds.
// for each node in the array, it then gets an array of the node's children,
and
// calls itself again with the array as argument (recursion)
function printData($nodeCollection)
{
global $startTags, $endTags;
// iterate through array
for ($x=0; $x<sizeof($nodeCollection); $x++)
{
print("<br>DBG:type=[" . $nodeCollection[$x]->type . "]</br>");
print("<br>DBG:tagname=[" . $nodeCollection[$x]->tagname . "]</br>");
print("<br>DBG:content=[" . $nodeCollection[$x]->content . "]</br>"); //
ALWAYS EMPTY
}
}
?>
</body>
</html>
======= PHP ========