First off, i got this code from the DOM XML: An Alternative to Expat article on this site. I tried the code in that just a few minutes go, after pulling considerable hair from my scalp trying to get my own working, and found that it doesnt do what it says on the tin either
Is there an update to that article?
here is my version
XML File:
<?xml version="1.0" encoding="UTF-8"?>
<STATUS_TABLE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="status.xsd">
<STATUS>
<ID_NUMBER>ID1</ID_NUMBER>
<DESCRIPTION>Open</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID2</ID_NUMBER>
<DESCRIPTION>In Progress</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID3</ID_NUMBER>
<DESCRIPTION>In Progress, Waiting For Replacement Part</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID4</ID_NUMBER>
<DESCRIPTION>In Progress, Waiting For Software</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID5</ID_NUMBER>
<DESCRIPTION>In Progress, Waiting For Collection By User</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID6</ID_NUMBER>
<DESCRIPTION>Provisionally Closed, Awaiting Confimation By User</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID7</ID_NUMBER>
<DESCRIPTION>Closed</DESCRIPTION>
</STATUS>
<STATUS>
<ID_NUMBER>ID8</ID_NUMBER>
<DESCRIPTION>Re-Activated</DESCRIPTION>
</STATUS>
</STATUS_TABLE>
My PHP Code:
<?php
# iterate through an array of nodes
# looking for a text node
# return its content
function get_content($parent)
{
$nodes = $parent->children();
foreach($nodes as $node)
if ($node->type == XML_TEXT_NODE)
return $node->content;
}
# get the content of a particular node
function find_content($parent,$name)
{
$nodes = $parent->children();
foreach ($nodes as $node)
if ($node->name == $name)
return get_content($node);
}
# load xml doc
$doc = xmldocfile("http://localhost/FYP/status_table.xml") or die("No File Found");
# get root Node (employees)
$root = $doc->root();
# get an array of employees' children
# that is each employee node
$status = $root->children();
# shift through the array
# and print out some employee data
print("Status Table<br/>"."<ul>");
while($stat = array_shift($status))
{
if ($stat->type == XML_TEXT_NODE)
continue;
$id = find_content($stat,"ID_NUMBER");
$desc = find_content($stat,"DESCRIPTION");
print("<li>".$id."--".$desc."</li>");
}
print("</ul>");
?>
has anyone gotten this to work, i need it fairly badly