Sitellite Application Framework
Class Tree         Index         All Elements

Class: XMLDoc

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

Class Overview


XMLDoc creates XML documents for you using DOM-like method calls.


Author(s)

Version

  • 2.8, 2003-07-11, $Id: Doc.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

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

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 125]
XMLDoc creates XML documents for you using DOM-like method calls.

XMLDoc is lightweight and fast, but does not deal with things like namespaces or encoding.

New in 1.2:

  • Added method query (), which allows users to traverse a set of nodes more easily and more legibly by using the most basic subset of XPath. Currently supports only the most basic syntax (/node1/node2/node3).
  • Added the $error property.
New in 1.4:
  • Added a $level parameter to the write() method, which is passed on to the root node. -1 signifies no auto-indenting.
New in 1.6:
  • Added two new methods: makeDoc() and writeToFile(). Also added a $filename property.
New in 1.8:
  • Added a $doctype property.
New in 2.0:
  • Added a new parameter to the query() method that lets you return an array of references to the resulting nodes instead of copies. This makes it easier to use the query() method in conjunction with document updates.
New in 2.2:
  • Added a makeMenu() method which uses saf.GUI.Menu to make it easier to display a document as a hierarchy using templates.
  • Updated query() to use the new saf.XML.Doc.Query class, which implements a simple query language based on XPath. See saf.XML.Doc.Query for specifics and examples.
  • Added makeObj() and makeRef() object methods.
New in 2.4:
  • Added a cache() method, which works with SloppyDOM's parseFromFile() method to make caching of XML documents super easy.
New in 2.6:
  • Added a propagateCallback() method, which compliments the new callback functionality in saf.XML.Doc.Node. For more info, see that package in saf/docs or DocReader.
New in 2.8:
  • Added an $xquery property, and modified query() to work with the new saf.XML.Doc.Query package.
New in 3.0:
  • Added a named alias for the $root node, so that it may be referred to by name for convenience. For example: $doc->_html. Note the underscore, used to prevent naming conflicts.

1 <?php
2
3 $doc = new XMLDoc ();
4
5 // create a basic xhtml document
6 $root =& $doc->addRoot ('html');
7
8 $head =& $root->addChild ('head');
9 $title =& $head->addChild ('title', 'Lux\'s Home Page');
10 $link =& $head->addChild ('link');
11 $link->setAttribute ('rel', 'stylesheet');
12 $link->setAttribute ('type', 'text/css');
13 $link->setAttribute ('href', 'http://127.0.0.4/css/site.css');
14
15 $body =& $root->addChild ('body');
16 $anchor_top =& $body->addChild ('a');
17 $anchor_top->setAttribute ('name', 'top');
18
19 $h1 =& $body->addChild ('h1', 'Lux\'s Home Page');
20 $img =& $body->addChild ('img');
21 $img->setAttribute ('src', '/pix/meeting.jpg');
22 $img->setAttribute ('alt', 'Welcome Image');
23 $img->setAttribute ('border', '0');
24 $img->setAttribute ('style', 'float: left');
25
26 $p1 =& $body->addChild ('p', 'Lux is a guy from Windsor, Ontario. He moved to Winnipeg in 1999.');
27 $p2 =& $body->addChild ('p', 'This page is just Lux\'s place to put up pictures of his cats, and other things you probably don\'t care to see.');
28 $copyright =& $body->addChild ('p', 'Copyright (c) 2001, Lux');
29 $copyright->setAttribute ('align', 'center');
30
31 echo $doc->write ();
32
33 ?>




Tags:

access:  public
version:  2.8, 2003-07-11, $Id: Doc.php,v 1.2 2005/07/06 15:30:56 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

$doctype =

[line 151]

May contain the entire DOCTYPE declaration tag, including the < and >.



Tags:

access:  public

Type:   mixed


[ Top ]

$encoding =

[line 142]

Encoding of the XML document. Default is 'utf-8'.

Please note: Actual encoding of data is not handled by these classes.




Tags:

access:  public

Type:   mixed


[ Top ]

$error =

[line 167]

Any internal error message involved in using this class.



Tags:

access:  public

Type:   mixed


[ Top ]

$filename =

[line 175]

If this object was read in from a file, it may be specified here.



Tags:

access:  public

Type:   mixed


[ Top ]

$root =

[line 159]

The root node of the XML document.



Tags:

access:  public

Type:   mixed


[ Top ]

$version =

[line 132]

XML version. Default is 1.0



Tags:

access:  public

Type:   mixed


[ Top ]

$xquery =

[line 183]

If query() has been called, this will contain the XMLDocQuery object.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor XMLDoc [line 193]

XMLDoc XMLDoc( [string $version = '1.0'], [string $encoding = 'utf-8'])

Constructor method.



Tags:

access:  public


Parameters:

string   $version  
string   $encoding  

[ Top ]

method addRoot [line 206]

resource &addRoot( string $name)

Creates the root node object of the document.



Tags:

access:  public


Parameters:

string   $name  

[ Top ]

method cache [line 372]

boolean cache( string $file)

Caches the current object to a file by serializing itself. Only updates

the cache file if the file modification time of the original file ($filename property must be set or you will get an error) has changed. This method works with SloppyDOM's parseFromFile() method to make caching XML files super easy.




Tags:

access:  public


Parameters:

string   $file  

[ Top ]

method makeDoc [line 278]

object &makeDoc( mixed $obj, string $toptag)

Takes an associative array or an object and returns an XMLDoc object created from it. $toptag is the name of the root node.



Tags:

access:  public


Parameters:

mixed   $obj  
string   $toptag  

[ Top ]

method makeMenu [line 331]

object makeMenu( )

Turns this document into a saf.GUI.Menu object, making it easy to display a document as a hierarchy using templates.



Tags:

access:  public


[ Top ]

method makeObj [line 345]

object makeObj( )

Calls the makeObj() method on the root node of the document tree.



Tags:

access:  public


[ Top ]

method makeRefObj [line 356]

object reference &makeRefObj( )

Calls the makeRefObj() method on the root node of the document tree.



Tags:

access:  public


[ Top ]

method propagateCallback [line 400]

void propagateCallback( string $startFunction, [string $endFunction = false], object reference &$obj)

Propagates a callback setting to the root node and all of its child nodes as well. Useful for setting a "default" callback setting which can then be overridden on a per-node basis, and for adding callbacks to documents which were recreated from a pre-existing data source.



Tags:

access:  public


Parameters:

string   $startFunction  
string   $endFunction  
object reference   $obj  

[ Top ]

method query [line 259]

array query( string $path, [boolean $ref = 0])

Returns a set of nodes, making it easier to traverse elements

in a loop, and making the code more legible as well. Accepts a very elementary and minimal language based on XPath (see saf.XML.Doc.Query for specifics and examples). Returns an array of references to matching nodes. Note: The $ref parameter is deprecated and doesn't do anything. Results are always returned as references.




Tags:

access:  public


Parameters:

string   $path  
boolean   $ref  

[ Top ]

method write [line 223]

string write( [integer $level = 0])

Generates the XML document you've created.



Tags:

access:  public


Parameters:

integer   $level  

[ Top ]

method writeToFile [line 304]

boolean writeToFile( [string $file = ''], [integer $level = 0])

Writes the current XMLDoc object to the specified file.



Tags:

access:  public


Parameters:

string   $file  
integer   $level  

[ Top ]


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