Justtechjobs.com Find a programming school near you






Online Campus Both


PHP and XML: using expat functions
The Extensible Markup Language is definitely something that most developers will want to add to their toolbox. XML is a W3C standard that is open, language neutral, API-neutral, streamable, textual, human-readable and is a way of bringing structured data to the web. XML is a subset of SGML and is not a markup language in itself but allows the author to define their own markup language where it is best suited for representing hierachical data. Now, parsing XML documents with PHP is not a topic that has been covered extensively as far as I have seen on the web and elsewhere. There is some very useful information in the PHP manual on XML parsing functions but this seems to be all the information that I could find. Other languages seem to have much more information and working examples of using XML than PHP does, so in this article I will attempt to do my part to change this.
I will walk the reader through a fairly simple application of XML that I used to implement a news system for my home page. I actually use this on my web site and it works really well. Feel free to use it on yours if you like. Ok, let's get started !
To use the XML parsing functions available to PHP you will need to have a module that supports XML installed on your web server. This means you will probably have to recompile your module to support XML, please look here for more info on how to do this. The XML parsing functions are really wrappers around the expat parser which is a SAX parser, which means Simple API for XML. The other kind of parser is a DOM parser, easier to use, an example of this is Microsoft's MSXML component which lets the programmer navigate through a tree style object accessing nodes and elements. The way the expat parser (or any SAX parser) allows you to parse an XML document is to specify callback functions for different tag types in the XML document being parsed. When the parser starts parsing your XML document and encounters a tag it will call your function and process the tag as specified in your function before continuing. You could look at this as an event driven way of parsing.
[ Next Page ]


Comments:
RE: How do I insert data in XML into MySQL tablespegas03/09/10 04:18
RE: Atributes pleaseShubhangi07/24/07 06:05
RE: Sending XML request via SSL?smita06/27/07 16:12
to obtain a window with XML_NITFEliza04/26/07 14:10
Explanationanandan02/14/06 07:27
±â³×½ººÏ µµÀü, 100¹è »¡¶óÁö°í ½¬¿öÁø ¿µ¾î¿ø¸® ÀÌÈÆ±â11/17/05 09:50
configure mysql php and apache Ashok jaydhar06/08/05 05:53
RE: Parsing XML Variable instead of filesmriti05/17/05 14:09
Parsing XML Variable instead of filematthew bagley04/29/05 12:04
php-mysql to xml to flash mx fatma04/16/05 05:35
website linkAl McNicoll02/07/05 10:00
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¿í12/05/04 10:12
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø12/03/04 08:33
½Å.¿ë.ºÒ.·®/Ä«.µå.¿¬.ü/´ë.Ãâ/È¥ÀÚ/ÇØ.°áÇÏ´Â/¹æ.¹ý±èÇö¼­11/30/04 18:58
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø11/25/04 04:24
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¿í11/24/04 08:18
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø11/17/04 06:21
10_ºÐ¾È¿¡ Çö.±Ý40¸¸_¿ø ¸¸.µé,±âÀÌÁ¤¿¬11/15/04 12:41
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæÇý11/13/04 06:45
RE: class for loading xml doc into arraychris10/01/03 08:44
An MVC framework for PHP using XSLTJustin Grant07/22/03 23:13
RE: xml as results of a formRicardo Garcia03/25/03 18:59
RE: How to convert HTML document to XML document jama03/06/03 04:26
empty xml tagstoshog02/24/03 00:04
RE: XML vs MySQL?pezagent12/25/02 11:08
RE: How to convert HTML document to XML documpezagent12/25/02 10:53
RE: Why XML filespezagent12/25/02 10:47
class for loading xml doc into arrayBrian Sanders12/12/02 15:23
PS. You don't need to set case-folding.../zureash12/11/02 16:41
RE: Case sensitivity/zureash12/11/02 09:54
RE: xml as results of a formHolger11/06/02 09:03
RE: XML vs MySQL?derek10/04/02 00:55
RE: XML vs MySQL?Mattias09/19/02 17:57
NewsBoy vs. newsboy in the example...Michael09/12/02 14:47
RE: What is "format" variable in this exampleRishi08/29/02 22:29
RE: XML vs MySQL?DWard08/28/02 21:09
RE: How about getting just one attributeBinaryGoddess08/28/02 20:01
Newb me could use a few answers...Duane08/28/02 19:17
RE: XML vs MySQL?ednark08/21/02 04:28
RE: What is "format" variable in this exampleStan08/09/02 18:30
RE: php-xml parserSugaya08/09/02 13:42
XML vs MySQL?Andy Christianson08/06/02 14:27
Size of XMl docBhuvnesh Kumar Sharma08/01/02 02:44
RE: What is "format" variable in this exampleTucker McLean07/30/02 21:59
What is "format" variable in this exampleJason Harley07/15/02 10:04
Search any attributes & values in XML Wajid Irfan06/25/02 10:21
php-mysql to xml to flash mxdreadyk06/24/02 04:54
RE: Expat & Sablotron tutorialJim Keohane06/10/02 17:24
Using PHP for form editingsucheta05/17/02 08:37
How to convert HTML document to XML document Hai Nguyen05/13/02 22:48
output controlArman05/07/02 20:18
Why XML filesJames Friesen04/29/02 00:07
RE: Store XML Data in an array to work with itRashmi Balakrishnan04/20/02 08:07
FormsDan03/28/02 18:07
RE: how to connect xml with phpSurya Desaraju03/28/02 13:37
RE: dispay data based on attributes?Surya Desaraju03/28/02 13:35
XML adding, editing, and deleting nodes w/PHPDavid Walker03/27/02 23:24
rdf utf-8 to sql mysqldavid d03/27/02 07:42
RE: how to connect xml with phpavar03/27/02 01:28
RE: How do I insert data in XML into MySQL tablesChris Hilbert03/25/02 17:02
RE: How do I insert data in XML into MySQL tablesRohit03/19/02 16:54
RE: xsl/xml/phpYves03/12/02 17:17
Store XML Data in an array to work with itPeter Autenrieth02/15/02 03:33
RE: Want Associative Array from xml stringibekowies01/28/02 11:45
RE: dispay data based on attributes?Gary Loescher01/17/02 01:48
dispay data based on attributes?ever01/14/02 19:22
dynamic parsinggaucho01/14/02 11:25
php-xml parsersands01/10/02 13:44
RE: How do I insert data in XML into MySQL tablesJawahar Rajamanickam01/07/02 00:50
Want Associative Array from xml stringS. Murali Krishnan01/02/02 06:50
Print, Send link to friend, and Save local?chris allen12/28/01 03:19
RE: How do I insert data in XML into MySQL tablesTobias Beuving12/14/01 15:05
RE: FLASH > PHP > XMLBertram Schaub11/28/01 05:27
xsl/xml/phpFrank11/21/01 06:00
RE: How do I insert data in XML into MySQL tablesRoland11/14/01 05:21
How do I insert data in XML into MySQL tablesRahul11/02/01 23:17
generating xml filesCathy10/30/01 04:05
Selecting Few storiespranay10/18/01 22:45
FLASH > PHP > XMLDirk10/17/01 23:53
RE: Sending XML request via SSL?kim10/14/01 22:12
How about getting just one attributeChad10/04/01 21:08
xml as results of a formMark08/23/01 01:32
RE: Atributes pleaseJames Taylor08/18/01 16:49
RE: XSL / XSLT anyone?Kevin Weir08/14/01 18:55
Expat & Sablotron tutorialjan janssen07/20/01 05:41
Any problems with PHP 4.0.6?rick07/03/01 08:38
RE: Atributes please - Now I've got itLuis Oliveira06/25/01 01:44
Atributes pleaseLuis Guerra Oliveira06/24/01 02:25
Very CoolDan Romanchik06/05/01 09:21
xml_parse generates internal server errorDan Romanchik06/04/01 12:01
Sending XML request via SSL?Dave05/17/01 08:44
Outputing the news as an arrayLuc05/08/01 08:41
NamespacesFang-Pin Chang05/04/01 14:02
RE: xslt and xml and PHP - possible???Urs Gehrig05/04/01 12:15
RE: attributesTommy04/27/01 07:25
xslt and xml and PHP - possible???Ralf Lodde03/04/01 15:50
Case sensitivityLiz03/04/01 03:26
XML is case sensitiveLiz03/04/01 02:59
Correct the examplealain03/03/01 10:10
NOTE to AUTHOR re: XML Justin Grant02/28/01 15:21
passing XML to PHP3Robin Baker02/02/01 14:03
NOTE to AUTHOR re: XML Allen01/31/01 21:47
RE: Problem : WML with PHPAllen01/31/01 21:45
It WORKS!!John Scrivener01/22/01 11:28
Problem : WML with PHPAlbert Tse01/07/01 03:18
RE: WML with PHPDavid Pettersson12/31/00 08:06
attributes? George12/22/00 21:24
RE:attributes ???George12/22/00 08:36
RE: WML with PHPGeorge12/22/00 08:20
WML with PHPMir12/19/00 10:21
RE: attributesMarc Antony Vose12/04/00 02:51
attributesGlen11/22/00 23:07
xml_set_objectJMK10/12/00 14:43
PHP and XMLtom10/11/00 15:01
RE: XSL / XSLT anyone?Alte Rego10/05/00 10:46
XSL / XSLT anyone?Mark Litchfield08/04/00 14:05
XSL / XSLT anyone?Mark Litchfield08/04/00 14:05
Thanks a whole bunch ;-)Tom Henry06/27/00 11:32
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.