Re: Problem with XML_Serializer

From: Date: Wed, 26 Oct 2005 23:24:28 +0000
Subject: Re: Problem with XML_Serializer
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21657@lists.php.net to get a copy of this message
John Malone wrote: > I'm kind of new to this XML stuff, and I've been trying to implement the XML > Serializer to unserialize a toolbar configuration like the following: > > <?xml version="1.0" encoding="utf-8"?> > <TOOLBAR icons="nav.bmp" hot_icons="nav.bmp" name="Google > Toolbar" > dllname="google_toolbar" id="tbs_toolbar_007370"> > <BUTTON caption="" hint="My Logo" id="tb_btn_vFSMgLLx" > img="" > command="redirect" > href="http://www.google.com"> > <MENU type="Split" img="demo_logo.bmp" hotimg="demo_logo.bmp" > id="tbs_menu_011299"> > <ITEM caption="Google Home Page" hint="Navigate to the Google home page" > img="" href="http://www.google.com" > command="redirect" > id="tbs_item_011508"/> > <ITEM caption="Google Links" hint="" img="" > id="tbs_item_016659"> > </MENU> > </BUTTON> > <SEPARATOR id="tbs_separator_000555"/> > <COMBO name="search" caption="" hint="Search Google" > limit="40" histmax="10" > id="tb_cmb_SVCgVyWG" command="keMdXGRo" dwidth="130" > kind="editable"> > </COMBO> > <BUTTON caption="Search Web" hint="Search the Web" > id="tb_btn_LKRIuoCj" > img="93" command="OGFnfNCz"> > <MENU type="Split" img="" hotimg="" > id="tbs_menu_019589"> > <ITEM caption="Search Web" hint="" img="" > command="pXyPVctx" > id="tbs_item_003161"/> > </MENU> > </BUTTON> > </TOOLBAR> > > The problem I am running into is that the order of the elements is important > to me, because this format determines how my toolbar will look. When I run > it through the unserializer, each button gets put into button[] and each > combo gets put into combo[] and my order is lost. What I'm looking to do is > have the elements brought into a toolbar[] and then I can check if button[] > is set for toolbar[0] or if combo is set for toolbar[0]. > > Any suggestions? XML_Serializer will not work for you, you'll have to use a DOM-like solution, or perhaps simplexml. These all require PHP 5. However, you can use the unmaintained domxml extension for PHP 4, if PHP 5 is not an option. You could also implement your own XML_Parser-based solution, which is a bit more work. See http://pear.php.net/XML_Parser Greg

« previous php.pear.general (#21657) next »