XML_PullParser
A token-based interface to the PHP expat XML library
version 1.3.2
Myron Turner
Utilites and Helper Functions

Contents         

Many of these methods have been discussed elsewhere in the Manual or used in examples. Check the Manual index for the relevant manual sections. Check the class documentation as well for other details.


Class Utilities
  1. bool XML_PullParser_pushbackToken ()
    Pushes current token back on the stack.
  2. array XML_PullParser_clearPbackStack ()
    Must be called if XML_PullParser_pushbackToken returns false
  3. void XML_PullParser_free ()
    This frees all resources. It should be called if a session is complete and another is going to be started or if the script is not at an end. Not neeeded if script exits at the end of the parsing session.
  4. array XML_PullParser_getCurrentElement ()
    This is a convenience method that returns the $current_element.
  5. array XML_PullParser_resetCurrentElement (array $cur_el)
    This method sets as the $current_element any valid tokenized array and returns a copy of the old $current_element. It makes it possible to set the $current_element to one needed in a portion of code and then to return it to its prevous value when finished.
  6. array XML_PullParser_unsetCurrentElement ()
    This sets the $current_element to an empty array and returns the a copy the $current_element that has been unset. Since many methods default to the $current_element or, if that is not set, to the current token, this method is a convenient way to switch back and forth between these two default arrays.
  7. boolean XML_PullParser_isCaseFolded ()
    Returns True if case-folding is in effect. With case-folding, all identifiers--element and attribute names--are converted up upper case. Case-folding is not a function of the underlying expat processer but is a function of the PHP implementation and occurs after the underlying processing has occurred. This means that the XML document itself must be well-formed; it must conform to the XML requirment that all identifiers must be case-sensitive, otherwise expat will report an error.
  8. string XML_PullParser_setDelimiter (string $delimiter)
    Sets the delimiter between the concatenated strings returned by XML_PullParser_getTextStripped and returns the previous delimiter. The default delimiter is a single space character (20 hex).
  9. array XML_PullParser_deleteBlanks ($token)
    Removes all blank array elements from $token. Tests all CDATA array elements against the PERL regex '/\w/' and deletes from the token array any CDATA which does not meet this test. This method should not be confused with XML_PullParser_excludeBlanks, a package level function which causes blank CDATa elments to be ignored during text processing, but not removed.

Package Level Utilities
The three CDATA functions (4,5,8) apply to XML_PullParser_getTextStripped and the text functions which use it( XML_PullParser_getText and XML_PullParser_getTextArray ). They can be called at any point and will apply to the next call to any of the affected methods. The other package level functions must be called in advance of the constructor; otherwise they have no effect.
  1. void XML_PullParser_caseSensitive (boolean $bool)
    Setting this to True turns off case-folding. See XML_PullParser_caseSensitive in the class documentation and XML_PullParser_isCaseFolded above.
  2. array XML_PullParser_declareChildElements (mixed $tags)
    Calling this function with either an array or variable list of child elements declares the $child_tags array. The $child_tags does not then have to be passed in to the constructor.
  3. array XML_PullParser_declareElements (mixed $tags)
    Calling this function with either an array or variable list of elements declares the $tags array. The $tags does not then have to be passed in to the constructor.
  4. void XML_PullParser_excludeBlanks (boolean $bool)
    Setting this to True causes blank text elements to be skipped. hese are text elements consisting solely of white space. This should be set to True when XML_PullParser_getTextArray is going to be used, because blank text elements can cause misalignment in the returned array. Compare this function with the class method XML_PullParser_deleteBlanks which is also listed in the class utilities above.
  5. void XML_PullParser_excludeBlanksStrict (boolean $bool)
    Setting this to True excludes from returned text any text element that does not meet the requirements of the PRE regular expression \w which represents all alphanumeric characters, the underscore, and the hyphen.
  6. void XML_PullParser_reInitTagArrays()
    This function must be called when more than one instance of XML_PullParser is created in the same script. It resets to the empty array the two global arrays which are used to initialilze the $tags and $child_tags arrays. Unless this function is called, the new instance will still hold array elements from the previous instance.
  7. void XML_PullParser_setReadLength ([integer $num = 2])
    This governs the maximum number of bytes read by the parser at each file access. The default read length is 8KB. This function will reset the read length in 4KB units, so that calling this function with a value of 4 will reset the the read length to 16KB. Read length can be of critical importance when processing large element strctures. If the data contained between the Start and End tags of a $tag or $child_tag exceeds the read length, parsing will become corrupted.
  8. void XML_PullParser_trimCdata (boolean $bool)
    Setting this to True causes all text elements to be passed through the PHP trim function.