I’m having issues getting to a parent node properly for a given node in PHP, using the DOM parser.
In the XML code below there is an outline tag, within it, items exist. Items can exist inside other items. Each item has one and only one value tag.
I can get to each item and value ok…but take for instance, the first three values. Each of which are a child of the previous item.
ColdFusion MX Upgrade (item)
–Dreamweaver MX (item under ColdFusion MX Upgrade)
–Importance to ColdFusion developers (item under Dreamweaver MX)
When I’m at the “Importance to ColdFusion developers” item and I get the parent…I get Dreamweaver MX along with a lot of other tags. All I want is, Dreamweaver MX. I tried using the first_child() function for a DOM node with no luck…I get nothing to show up.
Any and all help is most appreciated.
~panhead490
Here is my XML:
<outline>
<item>
<value>ColdFusion MX Upgrade</value>
<item>
<value>Dreamweaver MX</value>
<item>
<value>Importance to ColdFusion developers</value>
</item>
<item>
<value>Ease of transition from ColdFusion Studio</value>
</item>
<item>
<value>How to use Dreamweaver MX for ColdFusion Developers</value>
</item>
</item>
<item>
<value>ColdFusion Components</value>
<item>
<value>What are ColdFusion Components?</value>
</item>
<item>
<value>How are they used?</value>
</item>
</item>
</item>
<item>
<value>Integrating Flash MX and ColdFusion MX</value>
<item>
<value>Data Sources and Data Formats</value>
<item>
<value>What is a Data Source?</value>
</item>
<item>
<value>URL String, XML, Shared Objects, Text Files, Server-side Scripts</value>
</item>
</item>
</item>
<item>
<value>The LOADVARS Object</value>
<item>
<value>Creating a LoadVars Object</value>
</item>
<item>
<value>LoadVars Properties and Events</value>
</item>
</item>
<item>
<value>Flash Components with ColdFusion</value>
<item>
<value>Adding Flash Components</value>
<item>
<value>Radio Button Components</value>
</item>
<item>
<value>List Box Components</value>
</item>
<item>
<value>Check Box Components</value>
</item>
<item>
<value>Push Button Components</value>
</item>
<item>
<value>Scrolling Text Components</value>
</item>
</item>
</item>
</outline>
Here is the pertinent PHP code:
$node_root = $dom->document_element();
$child_nodes = $node_root->child_nodes();
// Find the outline element
foreach ($child_nodes as $value) {
if ($value->tagname == "outline") {
recurse_node($value);
}
}
function recurse_node($node, $parent_bool) {
if ($node->has_child_nodes()) {
$node_children = $node->child_nodes();
foreach( $node_children as $child) {
if ($child->tagname == "value") {
$node_parent = $child->parent_node();
$node_parent = $node_parent->parent_node();
//$node_parent = $node_parent->first_child();
echo "CONTENT: ".$child->get_content()."<br />";
echo "PARENT: ".$node_parent->get_content()."<br /><br />";
}
recurse_node($child);
}
}
}