Extending SimpleXML
problems with extending SimpleXML (which I intend to do so I can add automatic microformat support). Well I think I’ve come up with a solution.
I’ve created a class called ExtendXML that is completely extendable (see the other post for an explanation of why SimpleXML isn’t extendable) that provides all of the functionality of SimpleXML.
The initial call is similar to using SimpleXML (except I made the functions static class methods instead):
ExtendXML::load_string($xmlString, [$class, [$simpleClass]]);
ExtendXML::load_file($xmlFile, [$class, [$simpleClass]]);
The $class argument contains the name of the class that will be returned. This should extend ExtendXML and defaults to ExtendXML.
The $simpleClass argument contains the name of the SimpleXML class that will be passed to SimpleXML functions. This should extend SimpleXMLElement and defaults to SimpleXMLElement.
The object returned can then be used the same as a SimpleXMLElement object.
I haven’t tested it much or documented it yet, but it supports child tags (returning objects are of the class ExtendXML or whatever you specified), attributes and xpath expressions.
Comments
No Comments on Extending SimpleXML
-
Oliver on
Sat, 3rd Sep 2005 6:45 pm
-
Oliver on
Sat, 3rd Sep 2005 6:58 pm
-
Windsurf on
Mon, 7th Nov 2005 6:06 pm
-
Oliver on
Thu, 17th Nov 2005 8:54 pm
-
helga on
Sat, 17th Dec 2005 3:16 pm
-
Rick Jolly on
Tue, 20th Feb 2007 6:45 pm
-
Ze Thriller on
Mon, 2nd Jul 2007 2:59 pm
-
Oliver on
Tue, 3rd Jul 2007 5:40 pm
-
Web:Extend » Blog Archive » Extending SimpleXML on
Wed, 20th Feb 2008 9:20 pm
-
Very SimpleXML - PHPUGFFM - PHP User Group Frankfurt am Main on
Tue, 18th Mar 2008 12:37 pm
-
Priyan on
Sat, 10th May 2008 6:00 pm
< ![CDATA[A working (but limited) Microformats extension to SimpleXML:
< ![CDATA[ExtendXML::load_* now accept a fourth argument, $removeNameSpace that defaults to false.
When set to true it removes any default namespace declaration in the XML since SimpleXML doesn't play nicely with them. Although this is supposedly fixed in PHP 5.1.]]>
< ![CDATA[I would really like to see a working example. The thing I'm trying to do, is have two classes that extend simplexml, and store extra member properties. There is one xml file, say addressBook is the root node. Inside there are several 'person' nodes. I want to have one class handle the addressbook as a whole, and another class handle the person nodes as objects. One method of the person object would have a method like getName() and it would join firstName and lastName attributes and return them.
I am a bit foggy on how to do this with your class.]]>
sounds like just what i need.. got an example of how to use it?
I think what you have created is a wrapper class for simplexml.
< ![CDATA[I've tested your project and it seemed some advances functions for manipulating attributes/children nodes didn't work very well. So I've created my own class (XXS) based on yours and built a real documentation with it.
I'd like to publish it on sourceforge.net but i didn't see anything related to the license under whom the project ExtendXML is... so I don't know if I have the right to do this.
Of course your name and your website will be provided directly in the source code.
Please e-mail me as an answer :)]]>
Just for clarification, if anybody finds ExtendXML useful, you can do with it what you like
[...] ribute. Problem is, it won’t work with objects, arrays or resources. Someone already tried to do it. Sorry Oliver Brown, but I don’t like your solution. I shall th [...]
[...] schuetzki, 2007-05) Probleme und Wissenwertes beim Extenden von SimpleXML Overloading 1: Extending SimpleXML, Issues with extending SimpleXML, Microformats extension to Simp [...]
< ![CDATA[Hai
I am doing an exercise in Simple XML which loads the xml doc and do some query. When i tried a query to find all universities, it will give the list of universities.
Now i have to click one university name and i have to go to its own details which are stored in the xml will be retieved.
i could not get it, my code gives error.
also i could not pass the session variable to go the other page!
What can i do]]>
