XML Parser

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

XML Parser

Post by Sphenn »

Hey Everyone

I'm about to start writing an XML parser for a project I'm working on, and I thought I'd ask you guys for your thoughts before I start, hopefully avoiding some easy mistakes.

I'm trying to write a forum system that uses XML to work. Basically, each page calls an XML file that is read and each line is a command to be executed. For example:

Code: Select all

<command name="header" method="page_header" file="functions.php" etc></command>
<commandname="login" method="login_box" file="auth.php"></command>
First off, I'm doing this because it's then really easy to modify the system. Just add/remove lines and it's done.

So, is this a sound idea? Can anyone suggest a better way to do this/improve it? Also, If anyone has any experience with this sort of thing, and knows what I should watch out for, it would be appreciated. :D

Thanks for any and all input :)

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unless you have to support fairly old versions of php, xml parsers are built in, or readily available via pear or similar helper systems..

Using xml files sounds relatively okay, however to someone that doesn't know where things are stored in your code base, it may be difficult to learn (without really good documentation or an editor) and modify the output or whatever these control files actually do..
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Hi, and thanks for your input Feyd.

I've looked at some of the inbuilt parsers, but I'll take another closer look.

The goal of using XML is so that end users (admins) can easily change parts of the base code (add new features, remove others).

Again, thanks for your input. :D

Sphenn
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Sphenn wrote: The goal of using XML is so that end users (admins) can easily change parts of the base code (add new features, remove others).
Just curious, what does XML more here compared with alternatives (eg: cvs file or php))
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Hi

Sorry, I guess I should have explained further.

The way I'm building this system, there is the core module, and then admins can add various other features via plugins. By using XML, we can say, copy somefile.php to the includes directory, then open index.xml and include one line, and a new feature is added. I'm hoping that this'll avoid some of the issues that traditional "MODding" creates, such as not breaking existing code, etc. Because I'm using an OO approach, modules can just be dropped in and out easily (well, that's my goal anyway).

Hopefully, this makes more sense now, and thanks for your reply :D

Sphenn
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Sorry, I guess I should have explained further.
It's your thread, so you are allowed to steer the direction of this thread :) (If you think i'm going off-topic, just let me know and i shut up ;)
By using XML, we can say, copy somefile.php to the includes directory, then open index.xml and include one line, and a new feature is added.
I've got the feeling that my question is left unanswered. What is the extra value of using XML for this? Imho, it could be achieved as easily, perhaps even more easily (because it doesn't need a xml parser), with a simple config.php file where the user adds that new line.
I'm hoping that this'll avoid some of the issues that traditional "MODding" creates, such as not breaking existing code, etc.
I don't really see how the use of XML instead of PHP/CVS/database/whatever technology would make the problem go away.
Because I'm using an OO approach, modules can just be dropped in and out easily (well, that's my goal anyway).
I agree that a plugin system allows you to add/remove extra modules. I agree that with an OOP approach you make it easier to (unit/regression) test new/changed software modules..
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

timvw wrote:(If you think i'm going off-topic, just let me know and i shut up ;)
Not at all. That's why I started this thread, and I thank you for your suggestions :D
timvw wrote:
By using XML, we can say, copy somefile.php to the includes directory, then open index.xml and include one line, and a new feature is added.
I've got the feeling that my question is left unanswered. What is the extra value of using XML for this? Imho, it could be achieved as easily, perhaps even more easily (because it doesn't need a xml parser), with a simple config.php file where the user adds that new line.
I chose XML because it's got a simple syntax. It's a lot like HTML, so it's pretty easy to understand. The people who use this forum system will probably have very little experience, so this will ( I hope, look easier for them ).
timvw wrote:
I'm hoping that this'll avoid some of the issues that traditional "MODding" creates, such as not breaking existing code, etc.
I don't really see how the use of XML instead of PHP/CVS/database/whatever technology would make the problem go away.
Because it's a simpler syntax for the users to understand. Also, I don't want to use a DB because it makes offline editing harder, as well and more complicated for non techy users to understand.
timvw wrote:
Because I'm using an OO approach, modules can just be dropped in and out easily (well, that's my goal anyway).
I agree that a plugin system allows you to add/remove extra modules. I agree that with an OOP approach you make it easier to (unit/regression) test new/changed software modules..
Thanks for all of your input, and if you have any more, please keep it coming :)

Thanks again

Sphenn
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Forgot to mention this earlier Feyd, but thanks for your suggestion on using an inbuilt parser. It looks like SimpleXML is going to cut development time in half (at least).

Thanks again :D

Sphenn
Post Reply