note 106745 added to ref.xml

From: Date: Sat, 03 Dec 2011 02:56:08 +0000
Subject: note 106745 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-184878@lists.php.net to get a copy of this message
This is supplimental information for the "class xmlToArrayParser" (that follows) which was was included in my original Dec 2010 post. This is a fully functional error free, extensively tested php class unlike the posts that follow it. Key phrase: Fully functional, fully tested, error free XML To Array parser. <?php /** * class xmlToArrayParser * Notes: 1. 'attrib' and 'cdata' are keys added to the array when the element contains both attributes and content. 2. Ignores content that is not in between it's own set of tags. 3. Don't know if it recognizes processing instructions nor do I know about processing instructions. <\?some_pi some_attr="some_value"?> This is the same as a document declaration. 4. Empty elements are not included unless they have attributes. 5. Version 2.0, Dec. 2, 2011, added xml error reporting. Usage: $domObj = new xmlToArrayParser($xml); $elemVal = $domObj->array['element'] Or assign the entire array to its own variable: $domArr = $domObj->array; $elemVal = $domArr['element'] Example: $xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> <top> <element1>element content 1</element1> <element2 var2="val2" /> <element3 var3="val3" var4="val4">element content 3</element3> <element3 var5="val5">element content 4</element3> <element3 var6="val6" /> <element3>element content 7</element3> </top>'; $domObj = new xmlToArrayParser($xml); $domArr = $domObj->array; if($domObj->parse_error) echo $domObj->get_xml_error(); else print_r($domArr); On Success: $domArr['top']['element1'] => element content 1 $domArr['top']['element2']['attrib']['var2'] => val2 $domArr['top']['element3']['0']['attrib']['var3'] => val3 $domArr['top']['element3']['0']['attrib']['var4'] => val4 $domArr['top']['element3']['0']['cdata'] => element content 3 $domArr['top']['element3']['1']['attrib']['var5'] => val5 $domArr['top']['element3']['1']['cdata'] => element content 4 $domArr['top']['element3']['2']['attrib']['var6'] => val6 $domArr['top']['element3']['3'] => element content 7 On Error: Error Code [76] "Mismatched tag", at char 58 on line 3 * */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 206.75.202.212 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/106745 Del: integrated -- https://master.php.net/note/delete/106745/integrated Del: useless -- https://master.php.net/note/delete/106745/useless Del: bad code -- https://master.php.net/note/delete/106745/bad+code Del: spam -- https://master.php.net/note/delete/106745/spam Del: non-english -- https://master.php.net/note/delete/106745/non-english Del: in docs -- https://master.php.net/note/delete/106745/in+docs Del: other reasons-- https://master.php.net/note/delete/106745 Reject -- https://master.php.net/note/reject/106745 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184878) next »