<?php
////////////////////////////////////////////////////////////////////////
//Variables to be set
$coord_sys = "LL";
$datum = "WGS-84";
$format = "IDMS0";
$max_del = 30;
$msisdns = array();
////////////////////////////////////////////////////////////////////////
error_reporting(E_ALL);
//if (!$docnode = domxml_open_mem($theXML))
//echo "SOME ERROR";
//create a DOMXML object by reading the XML data from a file, the two lines above
can be
uncommented to
//create an object by reading it from a string
if (!$docnode = domxml_open_file("http://localhost/post/bot/xml/request.xml"))
echo "SOME ERROR";
//$docnode = create_text_node($theXML);
//get the root element of the document
$root = $docnode->document_element();
echo "ROOT: " . $root->node_name(); //display it (just in case)
if(!$childs = $root->child_nodes()) //creating a list of child nodes of the root,
should be an
array
echo "no child nodes<br>";
if (is_array($childs)) //just to check if what we got above really IS an array
(delete it if you are
sure that everything's working)
echo "\nARRAY\n";
else
echo "\nNONE\n";
while ($node = array_shift($childs)) //traversing the array of child-nodes of the
root
{
if (strcasecmp($node->node_name(), "client") == 0) //the second level of
hierarchy (refer
to the request.xml file for explanations)
{
if (!$client_children = $node->child_nodes())
echo "Error getting childer of client";
while ($extra_node = array_shift($client_children)) //here we only
output the data
about the child nodes, all the necessary data is contained in the children of the
next node
{
if (substr_count($extra_node->node_name(), "#") < 1)
echo "Client_content: " . $extra_node->node_name() . "
content: " .
$extra_node->get_content() . "\n";
}
}
if (strcasecmp($node->node_name(), "lir") == 0) //the node that contains the
necessary
information
{
if (!$client_children = $node->child_nodes()) //creating an array with
all the children
of it
echo "Error getting childer of client";
while ($extra_node = array_shift($client_children)) //traversing the
list of children
of "<LIR>"
{
$sh = 0;
//retrieving information from the GEO_INFO node
if (strcasecmp($extra_node->node_name(), "geo_info") == 0)
{
if (!$client_children_extra = $extra_node->child_nodes())
echo "Error getting childer of geo_info";
while ($array_node = array_shift($client_children_extra))
{
if (substr_count($array_node->node_name(), "#") < 1)
{
//the following set of IF's checks whether we
are looking at the node
the content of which corresponds to one of teh variables we want to set, and if so,
we set it
if (strcasecmp($array_node->node_name
(), "coord_sys") == 0)
$coord_sys = $array_node->get_content();
else if (strcasecmp($array_node->node_name
(), "datum") == 0)
$datum = $array_node->get_content();
else if (strcasecmp($array_node->node_name
(), "format") == 0)
$format = $array_node->get_content();
echo $array_node->node_name() . " content
(geo_info): " .
$array_node->get_content() . "\n";
}
}
}
//retieving data from MSISDN node
else if (strcasecmp($extra_node->node_name(), "msids") == 0)
{
if (!$client_children_extra = $extra_node->child_nodes())
echo "Error getting childer of client";
while ($array_node = array_shift($client_children_extra))
{
if (substr_count($array_node->node_name(), "#") < 1)
{
if (strcasecmp($array_node->node_name
(), "msid") == 0) //in this
case we should add a number to the msisdns array
{
$msisdns[$sh] = $array_node->get_content();
$sh++;
}
echo $array_node->node_name() . " content
(msids): " . $array_node-
>get_content() . "\n";
}
}
}
//retieving data from QoS node
else if (strcasecmp($extra_node->node_name(), "qos") == 0)
{
if (!$client_children_extra = $extra_node->child_nodes())
echo "Error getting childer of client";
while ($array_node = array_shift($client_children_extra))
{
if (substr_count($array_node->node_name(), "#") < 1)
{
echo $array_node->node_name() . " content
(qos): " . $array_node-
>get_content() . "\n";
if (strcasecmp($array_node->node_name
(), "qos") == 0)
$max_del = intval($array_node->get_content
());
}
}
}
}
}
}
//once again displaying the data we got from the XML (this time we use the variables
that
have been initialized)
reset($msisdns);
echo "\nCoordinate system: " . $coord_sys;
echo "\nDatum: " . $datum;
echo "\nFormat of data: " . $format;
echo "\nMaximum delay: " . $max_del;
//traverse through the array we created above
while ($elem = array_shift($msisdns))
echo "\nMSISDN: $elem";
?>