Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



XML Expat Parser in PHP

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2010
sivaranjan's Avatar
Member
 
Join Date: Aug 2006
Posts: 82
XML Expat Parser in PHP

Hello friends,
I have done the programs in PHP programming language to some extent. Now I want to know about the Expat Parser of an XML. Really speaking, I don't have any knowledge about the Expat Parser. So thought that you guys would help me to sort out my doubt. Please explain me what is XML Expat Parser in PHP. Any other information regarding this topic would be grateful..
__________________
The Gaming Machine:
Processor: Core 2 Duo E6400
Motherboard: Asus P5W DH Deluxe
RAM: 2GB XMS2 Corsair PC2-6400
Video: ATI Radeon X1900XT 512MB w/ Arctic Accellero
Drive: 74GB "WD Raptor" 10000RPM
Sound: Creative SoundBlaster X-Fi
Watercooling: *Soon* Zalman Reserator
Reply With Quote
  #2  
Old 25-02-2010
Warner's Avatar
Member
 
Join Date: Mar 2008
Posts: 349
Re: What is XML Expat Parser in PHP?

XML is used to describe data and to focus on what data is. An XML file describes the structure of the data. The built-in Expat parser makes it possible to process XML documents in PHP. I think that the Extensible Markup Language is definitely something that most developers will want to add to their toolbox. The main thing that you would have to know is, for using the XML parsing functions available to PHP you will need to have a module that supports XML installed on your web server. The XML parsing functions are really wrappers around the expat parser which is a SAX parser, which means Simple API for XML.
Reply With Quote
  #3  
Old 25-02-2010
Allan.d's Avatar
Member
 
Join Date: Mar 2008
Posts: 672
Re: About XML Expat Parser in PHP

An Expat Parser can work whether a DTD is associated to document or not, which is also known as non-validating. You can say that expat parser is an event-based parser. Event-based means it focuses on xml content, not on structure. You can also use 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. Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document.
Reply With Quote
  #4  
Old 25-02-2010
Viensterrr's Avatar
Member
 
Join Date: Jul 2006
Posts: 232
Re: What is Expat in PHP?

You should know about an Expat before going into the deep in PHP. For reading and updating an XML document, you will need an XML parser. You can also use XML parser while creating and manipulating an XML document.
XML parsers are categorized into two basic types :
  • Tree-based parser - This parser transforms an XML document into a tree structure. It analyzes the whole document, and provides access to the tree elements.
  • Event-based parser - Views an XML document as a series of events. When a specific event occurs, it calls a function to handle it.
__________________
Signatures reduce available bandwidth
Reply With Quote
  #5  
Old 25-02-2010
Solitario's Avatar
Member
 
Join Date: Aug 2006
Posts: 220
Re: Initializing the XML Parser in PHP

If you want to initialize the XML parser in PHP, you will have to define some handlers for different XML events. After defining some handlers you can then parse the XML file. The following example may help you for doing the same :
PHP Code:
<?php
$parser
=xml_parser_create();

function 
start($parser,$element_name,$element_attrs)
  {
  switch(
$element_name)
    {
    case 
"NOTE":
    echo 
"-- Note --<br />";
    break;
    case 
"TO":
    echo 
"To: ";
    break;
    case 
"FROM":
    echo 
"From: ";
    break;
    case 
"HEADING":
    echo 
"Heading: ";
    break;
    case 
"BODY":
    echo 
"Message: ";
    }
  }

function 
stop($parser,$element_name)
  {
  echo 
"<br />";
  }

function 
char($parser,$data)
  {
  echo 
$data;
  }

xml_set_element_handler($parser,"start","stop");

xml_set_character_data_handler($parser,"char");

$fp=fopen("test.xml","r");

while (
$data=fread($fp,4096))
  {
  
xml_parse($parser,$data,feof($fp)) or
  die (
sprintf("XML Error: %s at line %d",
  
xml_error_string(xml_get_error_code($parser)),
  
xml_get_current_line_number($parser)));
  }

xml_parser_free($parser);
?>
__________________
I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "XML Expat Parser in PHP"
Thread Thread Starter Forum Replies Last Post
.NET Configuration Parser Error on start up Barraq Operating Systems 5 11-04-2011 10:05 PM
Which JSON parser works on Windows Phone 7? Loyalpalm Portable Devices 3 27-10-2010 10:59 AM
How to get rid of the parser message window as it say value creation failed at line 451? KeJes Windows Software 3 30-01-2010 07:05 AM
Explanation on Parser, Sax and Dom Ernesto4 Software Development 3 21-11-2009 04:03 AM
Prefix not Bound to a namespace Error with XML parser Nihar Khan Software Development 3 02-03-2009 02:25 PM


All times are GMT +5.5. The time now is 04:02 AM.