note 85292 added to function.domelement-get-elements-by-tagname

From: Date: Sun, 24 Aug 2008 03:21:31 +0000
Subject: note 85292 added to function.domelement-get-elements-by-tagname
Groups: php.notes 
Request: Send a blank email to php-notes+get-143780@lists.php.net to get a copy of this message
This example uses get_elements_by_tagname() and child_nodes() to output the contents of the xml file. The sample xml file and php code are below. <?xml version="1.0" encoding="iso-8859-1"?> <dictionary> <entry> <word>Hello</word> <meaning>used to express a greeting</meaning> <example>Hello World!</example> </entry> </dictionary> <?php $xml_path = "/some/dir/dictionary.xml"; if (!$dom = domxml_open_file($xml_path)) { //the above requires absolube path exit("Could not access the XML source."); } $root = $dom->document_element(); //obtain the root $array_entry = $root->get_elements_by_tagname("entry"); //gets all <entry> DomElems foreach ($array_entry as $entry_dom_elem) { $childnodes = $entry_dom_elem->child_nodes(); foreach ($childnodes as $child) { //cycle thru <word>, <meaning>, <example> echo "node name: ".$child->tagname() . "; contains: " . $child->get_content()."<br>"; } } ?> The above code outputs: node name: word; contains: Hello node name: meaning; contains: used to express a greeting node name: example; contains: Hello World! ---- Server IP: 66.207.199.35 Probable Submitter: 99.231.176.37 ---- Manual Page -- http://www.php.net/manual/en/function.domelement-get-elements-by-tagname.php Edit -- https://master.php.net/note/edit/85292 Del: integrated -- https://master.php.net/note/delete/85292/integrated Del: useless -- https://master.php.net/note/delete/85292/useless Del: bad code -- https://master.php.net/note/delete/85292/bad+code Del: spam -- https://master.php.net/note/delete/85292/spam Del: non-english -- https://master.php.net/note/delete/85292/non-english Del: in docs -- https://master.php.net/note/delete/85292/in+docs Del: other reasons-- https://master.php.net/note/delete/85292 Reject -- https://master.php.net/note/reject/85292 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143780) next »