473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

XML parser

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
this?

Thanks,

Joshua Morgan

Feb 27 '06 #1
7 1967
On 27 Feb 2006 15:45:05 -0800, "Joshua Morgan" <jo***********@gmail.com> wrote:
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
this?


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

http://www.w3.org/TR/2004/REC-xml-20040204/

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:

http://www.google.co.uk/search?q=pure+php+xml+parser

(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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Feb 28 '06 #2

Joshua Morgan wrote:
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
this?

Thanks,

Joshua Morgan


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.

Feb 28 '06 #3
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.

Feb 28 '06 #4
"Joshua Morgan" <jo***********@gmail.com> writes:
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.


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

Reading and writing the XML DOM with PHP
Using the DOM library, SAX parser and regular expressions
http://www-128.ibm.com/developerwork...-lnxw06XML-PHP

--
Tomi Engdahl (http://www.iki.fi/then/)
Take a look at my electronics web links and documents at
http://www.epanorama.net/
Feb 28 '06 #5
Tomi Holger Engdahl said the following on 28/02/2006 12:01:
"Joshua Morgan" <jo***********@gmail.com> writes:
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.


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

Reading and writing the XML DOM with PHP
Using the DOM library, SAX parser and regular expressions
http://www-128.ibm.com/developerwork...-lnxw06XML-PHP


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.
--
Oli
Feb 28 '06 #6
Thanks, the DOM method seems the way to go, but is the DOMDocument
object supported in PHP4?

Feb 28 '06 #7
Yes. Take a look at http://www.php.net/manual/en/ref.domxml.php

--
Tony Marston

http://www.tonymarston.net
"Joshua Morgan" <jo***********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Thanks, the DOM method seems the way to go, but is the DOMDocument
object supported in PHP4?

Mar 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
11
by: Jean de Largentaye | last post by:
Hi, I need to parse a subset of C (a header file), and generate some unit tests for the functions listed in it. I thus need to parse the code, then rewrite function calls with wrong parameters....
1
by: Karalius, Joseph | last post by:
Can anyone explain what is happening here? I haven't found any useful info on Google yet. Thanks in advance. mmagnet:/home/jkaralius/src/zopeplone/Python-2.3.5 # make gcc -pthread -c...
3
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
2
by: Joel Hedlund | last post by:
Hi! I have a possibly dumb question about imports. I've written two python modules: parser.py ------------------------------------ class Parser(object): "my parser"...
5
by: thewarden | last post by:
I've come into a situation where I require to have BBCode parsed, this includes the standard tags supported by PEAR package HTML_BBCodeParser and custom BBCode tags I've added myself. My problem...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
18
by: Just Another Victim of the Ambient Morality | last post by:
Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: ...
0
by: arvindkgs | last post by:
Iam using c lexer that is flex generated and a c++ parser that is bison generated. i have modified the parser to acccept only string input. I am calling the parser function yyparse in a loop and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.