Re: DOMXML...

From: Date: Tue, 15 Jul 2003 23:50:22 +0000
Subject: Re: DOMXML...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-155341@lists.php.net to get a copy of this message
This is not an option for me... I'm writing a CMS and want to be able to do things for other users without specific compile options. -Michael Russell P Jones wrote:
This may not be what you are looking for, but the DOMXML object since PHP 4.0 works great --- you do have to compile PHP using the --with-dom For example... If i am dealing with the following structure... <contacts> <contact> <name>Russ</name> <phone>919.919.1919</phone> </contact> <contact> <name>Other</name> <phone>912.932.9328</phone> </contact> </contacts> and the name of this xml file is contacts.xml I would do the following... $xmlDoc = domxml_open_file('xml/contacts.xml'); $root = $xmlDoc->document_element(); $contacts = $root->children(); // this new $contacts file is an array of the xml tree. For example, to call up the first set of contact info, the info for russ, just use $contacts[0] // but there is more. say you want to learn about this contacts[0] node, such as pull the name russ. First, you have to get all the chirlden of this node... so you can do... $node_to_work_with = $contacts[0]->children(); // now this $node_to_work_with is an array with all the children, including the name, phone, etc. built in + information about these children. for example... echo $node_to_work_with[0]->get_content(); // that would print Russ echo $node_to_work_with[1]->get_content(); // that would print the Phone Number echo $node_to_work_with[0]->name(); // that would print "Name" as in the name of the node, which coincidentally happens to be name... --Russ
-- Pratt Museum IT Intern All programmers are playwrights and all computers are lousy actors.

« previous php.general (#155341) next »