Class eXcavator

Description

Class definition: eXcavator

Located in /eXcavator.inc (line 165)


	
			
Variable Summary
Method Summary
eXcavator eXcavator (string $doc, integer $doc_type)
boolean eXcavator_AND (integer $save_type, string $condition, mixed $xml, array $token)
void eXcavator_free ()
string eXcavator_getFormattedText (integer $which, $string $element, string $pattern)
void eXcavator_getInstances_Descendent ( $which,  $parent, [ $element = ""])
string eXcavator_getResultAsString ([boolean $html = False], [boolean $comment = False])
boolean eXcavator_OR (integer $save_type, string $condition, mixed $xml, array $token)
void eXcavator_Query (string $query)
boolean eXcavator_Relation (string $text_pat, string $cstyle_pat, string $condition, mixed $xml)
array eXcavator_showSchemeAsArray (integer $which, $string $element)
string eXcavator_showSchemeAsString (integer $which, $string $element)
void eXcavator_snapshot ( $which,  $parent)
boolean r_test (string $condition, string $element, array $token, integer $save)
mixed _checkCondition (string $condition, string $element, array $token, array &$found_array)
array _getAlternateBranch (integer $which, string $el)
mixed _getCondition (mixed $element,  $conditions)
integer _getOp (string $condition)
array _getResultAsBranchedArray (array $data)
boolean _hasRelation (integer $op, string $left, string $right)
mixed _isElement (mixed $token, mixed $condition, mixed $prev_array)
string _parseResult (mixed $result_array, boolean $html)
void _parseResultAsData ( $result_array)
array _parseResultAsDataStruct (mixed $result_array)
void _setDATA (integer $save_type, array $token)
Variables
array $eXcavator_childTags = Null (line 208)
  • var: passed into XML_PullParser for its $child_tags array
string $eXcavator_doc = null (line 176)

Either the XML document string or file name of XML document

integer $eXcavator_doc_format = null (line 185)

Either one of two defined constants: eXcavator_STRING or eXcavator_FILE

array $eXcavator_query = array() (line 222)
string $eXcavator_query_parent = Null (line 229)
string $eXcavator_query_str = Null (line 215)
array $eXcavator_result_array = Null (line 238)

This is the result array, created in _setDATA as conditions are evaluated as TRUE

array $eXcavator_Tags = Null (line 201)
  • var: passed into XML_PullParser for its $tags array
array $eXcavator_user_result_array = Null (line 247)

Used by eXcavator_getFormattedText

mixed $eXcavator_XML_PullParser = null (line 168)
reference $_parser = Null (line 194)
  • var: reference to XML_PullParser instance
Methods
Constructor eXcavator (line 260)

Constructor for eXcavator

eXcavator eXcavator (string $doc, integer $doc_type)
  • string $doc: file specification or XML document passed in as string
  • integer $doc_type: optional defined constant, either eXcavator_STRING or eXcavator_FILE
eXcavator_AND (line 540)

AND's expressions in $condition; loops through each expression in AND-ed sequence and returns false at first one to be found false, otherwise true

SYNTAX:
The syntax of _AND_ and _OR has two formats. One format applies if all the expressions in the condition are descendents of the context element to the left of the brackets and are of the same type:

  • vehicle[[@year>=2004 @make=Honda]]

But both _AND_ and _OR have a more comprehensive syntax, which allows for mixing of types and for the introduction of additional contexts into the condition. Here are the rules which govern the expanded syntax:

  1. Every AND-ed expression to the right of the _AND_ after the initial expression must use this syntax:
    target-element relational-expression
    For instance vehicle[[color CDATA=green]], which can be shortened to vehicle[[color=green]]
  2. The initial expression, i.e.the expression to the left of the first _AND_, can use the standard syntax for conditions, with one exception: it cannot use the shortcut for equality, as in color[geen] but must use the full expression: CDATA = green. On the other hand, it can also use the expanded syntax.
Some examples:
  1. vehicle[[dealer/avenue => CDATA < < Waverly _AND_ color = green _AND_ carfax @buyback=no]]
  2. first_name[[CDATA < < Douglas _AND_ first_name @middle_init=J]]
  3. owner[[ first_name < < Douglas _AND_ first_name @middle_init=J]]

Example 1 searches first for "Waverly" in the avenue element, then for "green" in the color element and then for the buyback attribute in the carfax element.
Example 2 tests for two relations in the first_name element. First, it tests for "Douglas" as cdata in the first_name element and then it tests for"J" in the middle_init attribute of first_name. Example 3 makes the same search as example 2, but it returns the entire owner element.

All the elements being searched must appear in the tokenized array $token, which is passed in as a parameter. That is, all of the items being evaluated must be descendents of a governing context-element. They don't have to be first-generation children, only descendents.

boolean eXcavator_AND (integer $save_type, string $condition, mixed $xml, array $token)
  • integer $save_type: either ATTR or CDATA, not currently used by method
  • string $condition
  • mixed $xml: either string if cdata or associative array if attribute, i.e. attribute_name=>value
  • array $token: the XML_PullParser tokenized array in which the current search is being conducted
eXcavator_free (line 1377)

Frees XML_PullParser resources

Must be called if running sequenctial instances of eXcavator, for instance in a loop

void eXcavator_free ()
eXcavator_getFormattedText (line 2017)

Gets formatted text based on a template

The template format is:
optional-text {selector} optional-text {selector} . . .

The optional text will be reproduced verbatim from the template. The selectors locate and identify data.

The basic selector consists of an element name:
{first_name}
or of the element name followed by a semi-colon and the name of an attribute:
{first_name;middle_init}

If there is more than one element of the same name in a context, it can be addressed using an indirect addressing mode:
{ owner=>city[1] } This selects the first city element in the owner element.

Text formatting is fully treated in the Manual.

  • return: text formatted in accordance with $pattern
string eXcavator_getFormattedText (integer $which, $string $element, string $pattern)
  • integer $which: result index
  • $string $element: name of element for display
  • string $pattern: template for formatted text
eXcavator_getInstances_Descendent (line 2127)
void eXcavator_getInstances_Descendent ( $which,  $parent, [ $element = ""])
  • $which
  • $parent
  • $element
eXcavator_getResultArray (line 1388)

Returns a copy of the raw result array eXcavator_result_array

array eXcavator_getResultArray ()
eXcavator_getResultAsData (line 1681)

Returns an indexed array of results in which each result is an associative array; its keys are the element names and their values are arrays which hold the element data

  [0] => Array (
   [element]=> array
    (
        [cdata] => string value
        [attr]  => semi-colon separated string of
                     attributes: name="value";name="value"
   )
  }

 [1] =>  Array {

  )

This array is suitable for passing in to a function for further processing.

This method loops through eXcavator_result_array sending one result at a time to _parseResultAsData where the result is converted to the associative array

array eXcavator_getResultAsData ()
eXcavator_getResultAsDataStruct (line 1647)

Deprecated

This is an internal function

array eXcavator_getResultAsDataStruct ()
eXcavator_getResultAsString (line 1703)

Converts $eXcavator_result_array to string in XML format

string eXcavator_getResultAsString ([boolean $html = False], [boolean $comment = False])
  • boolean $html: string will be suitable for browser is $html is True
  • boolean $comment: if True, individal results will be separated by comments that number results
eXcavator_getResultAsXMLDoc (line 1478)

Converts result from eXcavator_getResultAsString to

well-formed XML string

void eXcavator_getResultAsXMLDoc ()
eXcavator_getResultCount (line 1398)

Returns number of results found by query

integer eXcavator_getResultCount ()
eXcavator_OR (line 666)

OR's condition

loops through each expression in Or-ed sequence and returns true at first one to be found true, otherwise false

For details on how to use this method see eXcavator_AND. What is said there applies to eXcavator_OR, except for the fact that this method OR's instead of AND's the conditions.

boolean eXcavator_OR (integer $save_type, string $condition, mixed $xml, array $token)
  • integer $save_type: either ATTR or CDATA, not currently used by method
  • string $condition
  • mixed $xml: either string if cdata or associative array if attribute, i.e. attribute_name=>value
  • array $token: the XML_PullParser tokenized array in which the current search is being conducted
eXcavator_processQuery (line 1310)
void eXcavator_processQuery ()
eXcavator_Query (line 277)

Constructor for eXcavator

void eXcavator_Query (string $query)
  • string $query
eXcavator_Relation (line 788)

This parses the relationship of a condition expression and passes on the result to _hasRelation() where its truth value is determined

boolean eXcavator_Relation (string $text_pat, string $cstyle_pat, string $condition, mixed $xml)
  • string $text_pat: Text-style operator, i.e. "_INCL_", "_NE_}, etc.
  • string $cstyle_pat: C-style operator, i.e. '>', '<=', etc
  • string $condition
  • mixed $xml: either string if cdata or associative array if attribute, i.e. attribute_name=>value
eXcavator_showSchemeAsArray (line 1959)

An informational facility. Designed for use when creating patterns for eXcavator_getFormattedText.

It returns an array that is mapped to the requested element structure, showing the the elements it holds and their contents, both character data and attributes. In the output, duplicate element names are indexed using a triple underscore followed the its number, as in:

             ___1

The numbering begins with the second element, which is element___1. The first element found does not have an index attached to it.

This is the indexing that is used for direct addressing by eXcavator_getFormattedText.

This method returns only the first element named $element. If there is more than one element of the same name, for which a result is desired, then each subsequent element of that name must be addressed with its numeric index. If, for instance, an element named book has three authors, a request for book will return an array that includes author, author___1, and author___2. But if the request is for author, then only the first author element, with its children, will be returned. Separate requests would have to be made for author___1 and author___2.

array eXcavator_showSchemeAsArray (integer $which, $string $element)
  • integer $which: result index
  • $string $element: name of element for display
eXcavator_showSchemeAsString (line 1890)

An informational facility for use with eXcavator_getFormattedText. It returns a string which lists the names of all the elements held in the designated element structure.

The returned string is based on the array returned from eXcavator_showSchemeAsArray so that the commentary on that method applies to this as well.

  • return: list of elements in $eXcavator_user_result_array[$which][$element]
string eXcavator_showSchemeAsString (integer $which, $string $element)
  • integer $which: index of result in which $element resides
  • $string $element: name of element for display
eXcavator_snapshot (line 2150)
void eXcavator_snapshot ( $which,  $parent)
  • $which
  • $parent
r_test (line 1159)

This sends the condition string to _checkCondition(), where each condition is processed and the result is passed on to _setDATA()}.

If _checkCondition() finds that there is more than one condition in the condition string, it returns an array of the conditions contained in the condition string and then r_test() iterates through the array and sends one condition at a time back to _checkCondition().

boolean r_test (string $condition, string $element, array $token, integer $save)
  • string $condition
  • string $element: name of target element
  • array $token: XML_PullParser tokenized array
  • integer $save: will be > 0 if the condition is in double brackets
_checkCondition (line 872)

Parses the condition and determines the value of query

Determines operator type, type of condition (CDATA, ATTR), extracts the relevant children of $token and routes them to the proper operator method, collects each child that satisfies the condition in a result array and puts that in &$found_array or else if testing for the values of a descendent, it puts the ancestor array, which is extracted from $token, into &$found_array

main method variables:

  1. $save_type -- value passed to _setDATA in r_test(), either of two defines: CDATA or ATTR
  2. $op -- value of match operator: _NOT_, _GT_, etc

  • return: returns to r_test an array of sub conditions if it finds more than one condition in $condition; otherwise it returns the $save_type, which will be passed to _setDAta(), and by refence, the parameter &$found_array, which is the XML_PullParser_childXCL version of the result, which has been pulled from the parameter $token. r_test() sends this to _setData(), where it is saved in an array that conforms to the array type created by XML_PullParser_getChildren.
mixed _checkCondition (string $condition, string $element, array $token, array &$found_array)
  • string $condition
  • string $element: name of target element
  • array $token: XML_PullParser tokenized array
  • array &$found_array: XML_PullParser tokenized array
_getAlternateBranch (line 1803)

Called by eXcavator_getFormattedText to locate data held in descendent elements when the patterns use indirect addressing

  • return: associative array holding either text or attribute: ['cdata'] => text, OR ['attr'] => attribute_string (attribute name=value pairs separated by semi-colons)
array _getAlternateBranch (integer $which, string $el)
  • integer $which: the index of the target result
  • string $el: holds the context element, the descendent the arrow points to, and an index number, if any, e.g. [owner=>city[1]]
_getCondition (line 333)

Determines if there is an element which matches the element in the condition

  • return: Returns either the condition which matched the element or Null if not found
mixed _getCondition (mixed $element,  $conditions)
  • mixed $element: either a token or the name of anelement $conditions mixed $conditions either a single condition or any array of conditions
  • $conditions
_getOp (line 459)

extracts operator from condition

integer _getOp (string $condition)
  • string $condition
_getResultAsBranchedArray (line 1763)

Creates a key for each result element, which is a treated as a branch; called by _setUserResultArray to create the array needed by eXcavator_getFormattedText

What this method does, in effect, is to create an associative array of associative arrays, in which each element that has descendents is a separate associative array branching off the top level array. The associative array of descendents elements in turn holds the data in sets of associative arrays as described below.

This method works on a result array returned by _getResultAsDataStruct which creates a key for each element and if necessary numbers them and then sets each key to an array which holds the data for attributes and cdata:

   [element]=> array
             (
               [cdata] => string value
               [attr]  => semi-colon separated
                      string attributes: name="value";name="value"
            )
_getResultAsBranchedArray creates the structure $branches[$branch] at the top level. If the branch has descendent elements it creates a key for each of those under the branch: $branches[$branch][$el], and then sets these to their values, as described in the paragraph above.

array _getResultAsBranchedArray (array $data)
_getResultAsDataStruct (line 1624)

Loops through eXcavator_result_array to create raw array for eXcavator_getFormattedText

array _getResultAsDataStruct ()
_hasRelation (line 406)

Determines whether a relation is TRUE or FALSE

boolean _hasRelation (integer $op, string $left, string $right)
  • integer $op: constant defined relational operator
  • string $left: left side of operator, extracted from XML
  • string $right: right side of operator, user supplied value
_isElement (line 1200)

This method aligns each element with its conditions It passes the element name and its condition string to r_test(), which sends each condition to _checkCondition(), where the condition is evaluated.

  • return: either Constant or False
mixed _isElement (mixed $token, mixed $condition, mixed $prev_array)
_parseResult (line 1412)

Converts XML_PullParser tokenized array to string

Called by eXcavator_getResultAsString which loops through the result array one result at a time, sending it here for string-izing

string _parseResult (mixed $result_array, boolean $html)
  • boolean $html: returns string suitable for display in browser if True
_parseResultAsData (line 1488)
void _parseResultAsData ( $result_array)
  • $result_array
_parseResultAsDataStruct (line 1548)

Does work of creating arrays for eXcavator_result_array

array _parseResultAsDataStruct (mixed $result_array)
_setDATA (line 1262)

Creates result array in conformance with XML_PullParser_getChildren()

As conditions are met in _checkCondition, the results are passed to this method by r_test, and they are saved here in the result array eXcavator_result_array

void _setDATA (integer $save_type, array $token)
  • integer $save_type
  • array $token: XML_PullParser tokenized array
_setUserResultArray (line 1977)

Converts array returned by _getResultAsDataStruct()

to form suitable for use by eXcavator_getFormattedText

void _setUserResultArray ()

Documentation generated on Mon, 30 Oct 2006 07:00:59 -0500 by phpDocumentor 1.3.0RC6