WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A simple example of using PHP DOMXML functions
Categories : PHP, XML Click here to Update Your Picture
Peter Tatischev
Date : May 20th 2002
Grade : 2 of 5 (graded 5 times)
Viewed : 9873
File : request.xml
Images : No Images for this code example.
Search : More code by Peter Tatischev
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?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";
?>



RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
A very basic and fast XML parser
Categories : PHP, PHP Classes, XML
Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS)
RSS parser using PHP5 and simpleXML
Categories : Rich Site Summary (RSS), PHP, XML
Glossword - glossary compiler
Categories : Content Management, PHP, MySQL, XML
Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
XML easy parser
Categories : PHP, XML
MySQL or SQL Query to XML Output
Categories : PHP, MySQL, XML, Databases
XML Menu
Categories : PHP, PHP Classes, Navigation, XML, XSL
Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories
Trivia Quiz program using XML, XSLT and PHP
Categories : PHP, XML, XSLT
Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript.
Categories : PHP, Java Script, DOM XML, XML, Arrays
SAPIPROCESSOR - is a compact XML-based CMS toolkit
Categories : PHP, Content Management, XML
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
On-the-fly drop down menu from a txt or xml file
Categories : PHP, XML, HTML and PHP