Sitellite Application Framework
Class Tree         Index         All Elements

Class: XMLDocQuery

Source Location: Program_Root/XML/Doc/Query.php

Class Overview

Parser
   |
   --XMLDocQuery

XMLDocQuery provides XPath-compatible searching and referencing capabilities to the XMLDoc package. Here is a list of supported Xpath features:


Author(s)

Version

  • 2.0, 2003-01-20, $Id: Query.php,v 1.3 2005/10/16 02:52:14 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods

Class: Parser

Parser::Parser()
Constructor method.
Parser::addInternal()
Alias of addToken().
Parser::addToken()
Defines a token whose callback function has the same name as
Parser::makeRegex()
Turns the $tokens list into a regular expression.
Parser::parse()
This is the mainloop of the parser.
Parser::_default()
This is the default token handler. It merely returns

Class Details

[line 107]
XMLDocQuery provides XPath-compatible searching and referencing capabilities to the XMLDoc package. Here is a list of supported Xpath features:

  • /nodeName and //nodeName references
  • /nodeName[1] numbered references (counting starts from 1, not 0).
  • /nodeName[@attrName="attrValue"] references
  • /@attrName attribute references
  • /nodeName/@attrName = "some value" conditions
Features specifically not supported from the Xpath standard are:

  • Axes, ie. child::someNodeName
  • Relative operators, ie. ./childNode, ../siblingNode, and *
  • Functions, ie. //item/title/upper-case(.)
For more information about Xpath, see http://www.w3.org/TR/xpath.

Query Examples --------------

(Based on an XHTML document structure.)

/html/body/h1 returns all h1 tags directly below the body tag. Elements are returned as DocNode object references.

/html/body//p returns all p tags anywhere inside the body.

//p returns all p tags anywhere, even outside the body.

//a/@href returns all links in the document, as an array of DocAttr object references.

/html/body//p[1] returns the first p tag found inside the body.

//table/tr[1]/td[1] returns the first cell (top-left) of each table.

//map[@name="top-navbar"] returns the node <map name="top-navbar"></map>.

/html/body/h1 = "Welcome" returns a true or false value, depending on whether the first h1 tag contains the string "Welcome".

/html/head/meta returns all of the meta tags.

/html/head/meta[@name="description"] returns the meta description tag.

This class is not usually called directly, but can be accessed through the query() method of the XMLDoc and XMLNode classes.

New in 2.0:

  • Rewritten from scratch using the saf.Parser package. Should be more stable now and is more featureful now.
  • New features added: attribute references, conditions, and fixed the numbebred references to begin counting from 1 instead of 0, which is now compatible with the Xpath standard.
Historical:

New in 1.2:

  • Fixed a bug where the use of namespaces caused matching to fail.

1 <?php
2
3 $xq = new XMLDocQuery ($xhtml_doc);
4
5 $res = $xq->query ('/html/head/title');
6
7 ? >




Tags:

access:  public
version:  2.0, 2003-01-20, $Id: Query.php,v 1.3 2005/10/16 02:52:14 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$doc =

[line 131]

Set this to the current XMLDoc or XMLNode object.



Tags:

access:  public

Type:   mixed


[ Top ]

$error =  false

[line 139]

If an error occurs, this will contain the message.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor XMLDocQuery [line 147]

XMLDocQuery XMLDocQuery( )

Constructor method.



Tags:

access:  public


[ Top ]

method evalCond [line 235]

boolean evalCond( string $op, string $one, string $two)

Evaluates a condition specified by the $op operator, and the two sides to compare.



Tags:

access:  public


Parameters:

string   $op  
string   $one  
string   $two  

[ Top ]

method evaluate [line 278]

boolean evaluate( object reference &$node, string $struct)

Evaluates whether the current $node matches the name and/or qualifications in $struct, which is created by the various callback methods.



Tags:

access:  public


Parameters:

object reference   $node  
string   $struct  

[ Top ]

method getNodes [line 303]

array &getNodes( object reference &$nodes, mixed $name, [boolean $recursive = false])

Searches (optionally recursively) through the $nodes list, calling evaluate() to determine whether each node matches the current piece of the query (specified by $name).



Tags:

access:  public


Parameters:

object reference   $nodes  
mixed   $name  
boolean   $recursive  

[ Top ]

method query [line 172]

mixed &query( object reference &$rootNode, string $query)

Executes a search against the XML tree structure using the specified $query. Usually returns an array of matching nodes, either XMLDocNode or XMLDocAttr objects, or a boolean value on conditional queries.



Tags:

access:  public


Parameters:

object reference   $rootNode  
string   $query  

[ Top ]

method queryFile [line 208]

mixed queryFile( string $file, string $query)

Executes a search against the XML tree structure in the specified $file, using the specified $query. Returns the output of calling query() on the parsed file.



Tags:

access:  public


Parameters:

string   $file  
string   $query  

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:18:47 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2