note 60121 added to ref.xml
| From: | CJ at osu1 dot php dot net | Date: | Tue, 27 Dec 2005 13:19:37 +0000 |
| Subject: | note 60121 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100783@lists.php.net to get a copy of this message | ||
i've been looking for some code wich makes me a well usable array, from "any" xml.
but though here are extremely good implementations of parsers i havnt found it, so i made up a class
wich makes an easy useable array. probably not rockstable but well formed xml worx (well it should)
<?php
ini_set("display_errors","1");
class q{
//builds ARRAY from XML
function xmltoarray($xml);
//builds ARRAY from VALS recived from parser
function valtoar(&$val,&$pos,&$cdata);
//rebuild XML from ARRAY
function arraytoxml($cjxml,$depth=0);
}
$ix=new q();
$erg =$ix->xmltoarray('<object
name="name2">alphatext?<element name="name"
id="1"><![CDATA[text abc <de]]></element>objettext2<element
name="name" id="2">text2</element><element name="name"
id="3" /><!-- any --> objekttext</object>');
print_r($erg);
$ergt=$ix->arraytoxml($erg);
print($ergt);
$ergi=$ix->arraytoxml($erg,-1);
print($ergi);
$erg =$ix->xmltoarray($ergi);
print_r($erg);
//it produes an array wich can be easiely used by programs without any special cases
//its structure is
/*
[tag]
[#]
["attributes"]
[attribute]=>string
["values"]
[#]=>string
["elements"]
[tag]
[#]
["attributes"]
[attribute]=>string
["values"]
[#]=>string
["elements"]
[tag]
[#]
.......
# means any number
tag means the tag of the element
attribut means the attribut
.......
*/
//btw. array 2 xml builds the xml from this array, u see the code is simple since the
array has no special cases
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60121
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60121&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60121&report=yes
Search -- http://master.php.net/manage/user-notes.php