XML parser

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hey all,

I want to create my own XML parser that is completely independent of
PHP version (i want it to run on both PHP 4 and 5), and to also not
require any dependencies (so that the user DOESN'T have to compile php
with --with-xml).

Can someone point me in the right direction as to how I can go about


Joshua Morgan

Re: XML parser

Quoted text here. Click to load it

 If you really want to write one yourself, perhaps for fun (?!) then:


 And then you probably want to look up "DOM" and "SAX" parsers for the two main
approaches to parsing XML.

 Alternatively you can avoid re-inventing the wheel:


 (Is it really so much of a hardship to compile with XML support though? PHP4
even comes with a bundled copy of the expat library, and PHP5 is a bit fiddly
to compile _without_ XML support, IIRC, since some other extensions rely on it)

Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Re: XML parser

Joshua Morgan wrote:
Quoted text here. Click to load it

Are you parsing XML files of a particular schema or you want a general
XML parser? For the former purpose, I have often found it quite easy to
extract the necessary info using regular expressions.

Re: XML parser

A general XML parser, and that is actually what I was considering
doing, using regular expression to pull out the data and put it into a
nice array that can be used by some functions.

Re: XML parser

Quoted text here. Click to load it

You can find examples of reading XML files using three different  
techniques (including that regular expression method) at this  

Reading and writing the XML DOM with PHP
Using the DOM library, SAX parser and regular expressions

Tomi Engdahl (http://www.iki.fi/then /)
Take a look at my electronics web links and documents at  

Re: XML parser

Tomi Holger Engdahl said the following on 28/02/2006 12:01:
Quoted text here. Click to load it

And as that article says, use of regular expressions to "parse" XML is a  
bad idea unless you're absolutely sure that the XML string/file is  
well-formed and valid.


Re: XML parser

Thanks, the DOM method seems the way to go, but is the DOMDocument
object supported in PHP4?

Re: XML parser

Yes. Take a look at http://www.php.net/manual/en/ref.domxml.php

Tony Marston


Quoted text here. Click to load it

Site Timeline