# parser/ExpatParser.php

## \ExpatParser
jump to top

Package: phing\parser

This class is a wrapper for the PHP's internal expat parser.

It takes an XML file represented by a abstract path name, and starts parsing the file and calling the different "trap" methods inherited from the AbstractParser class.

Those methods then invoke the represenatative methods in the registered handler classes.

Parent(s)
  \AbstractSAXParser
Access
  public
Author
  Andreas Aderhold
Copyright
  © 2001,2002 THYRELL. All rights reserved
Version
  $Revision: 526 $ $Date: 2009-08-11 14:11:17 +0200 (Tue, 11 Aug 2009) $

### Properties

`$buffer= '4096'`
Default value `4096` Details

Type

`$error_string= '""'`
Default value`""`Details

Type

`$file= ''`
Details

Type

`$handler= ''`
inherited

The AbstractHandler object.

Inherited from: \AbstractSAXParser::$handler
Details

Type
Inherited_from
  \AbstractSAXParser::$handler

`$line= '0'`
Default value `0` Details

Type

`\Location $location= ''`

Current cursor pos in XML file.
Details

Type
  \Location

`resource $parser= ''`

Details

Type
  resource

`\Reader $reader= ''`

Details

Type
  \Reader

### Methods

`__construct( \Reader $reader, string $filename = null ) : void`

Constructs a new ExpatParser object.

The constructor accepts a PhingFile object that represents the filename for the file to be parsed. It sets up php's internal expat parser and options.

Parameters

Name | Type | Description
--- | --- | ---
$reader | \Reader | The Reader Object that is to be read from.
$filename | string | Filename to read.

Throws

Exception | Description
--- | ---
\Exception | if the given argument is not a PhingFile object

`characters( resource $parser, string $data ) : void`
inherited

Method that gets invoked when the parser runs over CDATA.

Inherited from: \AbstractSAXParser::characters()

This method is called by PHP's internal parser functions and registered in the actual parser implementation.

It gives control to the current active handler object by calling the

    characters()

method. That processes the given CDATA.

Parameters

Name | Type | Description
--- | --- | ---
$parser | resource | php's internal parser handle.
$data | string | the CDATA

Throws

Exception | Description
--- | ---
\Exception | - Exceptions may be thrown by the Handler

`endElement( object $parser, string $name ) : void`
inherited

Method that gets invoked when the parser runs over a XML close element.

Inherited from: \AbstractSAXParser::endElement()

This method is called by PHP's internal parser funcitons and registered in the actual parser implementation.

It gives control to the current active handler object by calling the

    endElement()

method.

Parameters

Name | Type | Description
--- | --- | ---
$parser | object | the php's internal parser handle
$name | string | the closing tag name

Throws

Exception | Description
--- | ---
\Exception | - Exceptions may be thrown by the Handler

`getLocation( ) : object`

Returns the location object of the current parsed element. It describes the location of the element within the XML file (line, char)

Returns

Type | Description
--- | ---
object | the location of the current parser

Details

Access
  public

`parse( ) : int`

Starts the parsing process.

Returns

Type | Description
--- | ---
int | 1 if the parsing succeeded

Throws

Exception | Description
--- | ---
\ExpatParseException | if something gone wrong during parsing
\IOException | if XML file can not be accessed

Details

Access
  public

`parserSetOption( string $opt, $val ) : boolean`

Override PHP's parser default settings, created in the constructor.

Parameters

Name | Type | Description
--- | --- | ---
$opt | string | the option to set
$val |  |

Returns

Type | Description
--- | ---
boolean | true if the option could be set, otherwise false

Throws

Exception | Description
--- | ---
mixed | the value to set

Details

Access
  public

`setHandler( \AbstractHandler $obj ) : void`
inherited

Sets the current element handler object for this parser. Usually this is an object using extending "AbstractHandler".

Inherited from: \AbstractSAXParser::setHandler()
Parameters

Name | Type | Description
--- | --- | ---
$obj | \AbstractHandler | The handler object.

`startElement( object $parser, string $name, array $attribs ) : void`
inherited

Method that gets invoked when the parser runs over a XML start element.

Inherited from: \AbstractSAXParser::startElement()

This method is called by PHP's internal parser functions and registered in the actual parser implementation. It gives control to the current active handler object by calling the

    startElement()

method.

Parameters

Name | Type | Description
--- | --- | ---
$parser | object | the php's internal parser handle
$name | string | the open tag name
$attribs | array | the tag's attributes if any

Throws

Exception | Description
--- | ---
\Exception | - Exceptions may be thrown by the Handler

Documentation was generated by DocBlox 0.15.1.