Open Journal Systems  3.3.0
XMLParser Class Reference

Public Member Functions

 __construct ()
 
 addError ($error)
 
 createParser ()
 
 destroyParser ($parser)
 
 getErrors ()
 
 getStatus ()
 
 parse ($file)
 
 parseStruct ($file, $tagsToMatch=array())
 
 parseText ($text)
 
 parseTextStruct ($text, $tagsToMatch=array())
 
 setHandler ($handler)
 

Data Fields

 $errors
 
 $handler
 

Protected Member Functions

 _getStream ($filenameOrUrl)
 

Detailed Description

Generic class for parsing an XML document into a data structure.

Definition at line 28 of file XMLParser.inc.php.

Constructor & Destructor Documentation

◆ __construct()

XMLParser::__construct ( )

Constructor. Initialize parser and set parser options.

Definition at line 45 of file XMLParser.inc.php.

Member Function Documentation

◆ _getStream()

XMLParser::_getStream (   $filenameOrUrl)
protected

Get a PSR7 stream given a filename or URL.

Parameters
$filenameOrUrl
Returns
\GuzzleHttp\Psr7\Stream|null

Definition at line 115 of file XMLParser.inc.php.

References PKPApplication\get(), and GuzzleHttp\Psr7\stream_for().

Referenced by parse(), and parseStruct().

◆ addError()

XMLParser::addError (   $error)

Add an error to the current error list

Parameters
$errorstring

Definition at line 133 of file XMLParser.inc.php.

Referenced by parse(), and parseText().

◆ createParser()

XMLParser::createParser ( )

Initialize a new XML parser.

Returns
resource

Definition at line 218 of file XMLParser.inc.php.

Referenced by parse(), parseText(), and parseTextStruct().

◆ destroyParser()

XMLParser::destroyParser (   $parser)

Destroy XML parser.

Parameters
$parserresource

Definition at line 229 of file XMLParser.inc.php.

Referenced by parse(), parseText(), and parseTextStruct().

◆ getErrors()

XMLParser::getErrors ( )

Get the current list of errors

Definition at line 140 of file XMLParser.inc.php.

References $errors.

◆ getStatus()

XMLParser::getStatus ( )

Determine whether or not the parser encountered an error (false) or completed successfully (true)

Returns
boolean

Definition at line 149 of file XMLParser.inc.php.

◆ parse()

XMLParser::parse (   $file)

Parse an XML file using the specified handler. If no handler has been specified, XMLParserDOMHandler is used by default, returning a tree structure representing the document.

Parameters
$filestring full path to the XML file
Returns
object|false actual return type depends on the handler

Definition at line 80 of file XMLParser.inc.php.

References $handler, _getStream(), addError(), createParser(), destroyParser(), and setHandler().

◆ parseStruct()

XMLParser::parseStruct (   $file,
  $tagsToMatch = array() 
)

Parse an XML file using xml_parse_into_struct and return data in an array. This is best suited for XML documents with fairly simple structure.

Parameters
$filestring full path to the XML file
$tagsToMatcharray optional, if set tags not in the array will be skipped
Returns
array? a struct of the form ($TAG => array('attributes' => array( ... ), 'value' => $VALUE), ... )

Definition at line 205 of file XMLParser.inc.php.

References _getStream(), and parseTextStruct().

◆ parseText()

XMLParser::parseText (   $text)

Definition at line 49 of file XMLParser.inc.php.

References $handler, addError(), createParser(), destroyParser(), and setHandler().

◆ parseTextStruct()

XMLParser::parseTextStruct (   $text,
  $tagsToMatch = array() 
)

Parse XML data using xml_parse_into_struct and return data in an array. This is best suited for XML documents with fairly simple structure.

Parameters
$textstring XML data
$tagsToMatcharray optional, if set tags not in the array will be skipped
Returns
array? a struct of the form ($TAG => array('attributes' => array( ... ), 'value' => $VALUE), ... )

Definition at line 168 of file XMLParser.inc.php.

References createParser(), and destroyParser().

Referenced by parseStruct().

◆ setHandler()

XMLParser::setHandler (   $handler)

Set the handler to use for parse(...).

Parameters
$handlerXMLParserHandler

Definition at line 157 of file XMLParser.inc.php.

References $handler.

Referenced by parse(), and parseText().

Field Documentation

◆ $errors

array XMLParser::$errors

List of error strings

Definition at line 39 of file XMLParser.inc.php.

Referenced by getErrors().

◆ $handler

object XMLParser::$handler

instance of XMLParserHandler

Definition at line 33 of file XMLParser.inc.php.

Referenced by parse(), parseText(), and setHandler().


The documentation for this class was generated from the following file: