InterJinn

Development Framework For PHP

interJinn
Class JinnSimpleXml (EXPERIMENTAL)

public class JinnSimpleXml
extends JinnBaseService

This services implements an API for setting and retrieving simplistic information in an XML document. By simple the API expects that the content of a tag will not be a combination of text and sub-tags.

Given the simple nature of this API, no validation of the XML wil be performed against a schema or DTD. The engine presumes the XML is well-formed and follows whatever structure it is supposed to follow. Generally speaking XML data from webservices will be correct.

Example:
$xml =
   
'<lev1>'."\n"
   
.'  <lev2>'."\n";
   .
'    <lev3>'."\n";
   .
'      <lev4>'."\n";
   .
'        <lev5>apple</lev5>'."\n"
   
.'        <lev5 citrus="true">orange</lev5>'."\n"
   
.'        <lev5>plum</lev5>'."\n"
   
.'      </lev4>'."\n";
   .
'    </lev3>'."\n";
   .
'  </lev2>'."\n";
   .
'</lev1>'."\n";

$xmlObj = &$this->getServiceRef'simpleXml' );
$xmlObj->parse$xml );

//
// Prints 'apple'
//
echo $xmlObj->getValue'lev1/lev2/lev3/lev4/lev5' );

//
// Prints 'orange'
//
echo $xmlObj->getValue'lev1/lev2/lev3/lev4/lev5#1' );

//
// Puts the target path's subtree into focus.
//
$xmlObj->focus'lev1/lev2/lev3/lev4/lev5' );

//
// Prints 'plum'
//
echo $xmlObj->getValue'#2' );

//
// Loops through all of the <lev5/> values and prints each
// (don't forget <lev5/> is currently in focus).
//
foreach( $xmlObj->getIndexes() as $index )
{
    echo 
$xmlObj->getValue"#$index" );
}

//
// Echo's the citrus attribute for each <lev5/> entry.
//
foreach( $xmlObj->getIndexes() as $index )
{
    echo 
$xmlObj->getValue"#$index@citrus" );
}

//
// Reset focus back to root.
//
$xmlObj->focusReset();

//
// Loops through all of the <lev5/> values and prints each.
//
foreach( $xmlObj->getIndexes'lev1/lev2/lev3/lev4/lev5' ) as $index )
{
    echo 
$xmlObj->getValue"lev1/lev2/lev3/lev4/lev5#$index" );
}


Direct Known Subclasses

Method Summary
public JinnSimpleXml( )

The constructor.
protected array ___createGroup( )

Groups are used to group together nodes with the same name into an indexed lookup map.
protected array ___createNode( )

Used to construct the node tree.
public bool ___focusCriteriaRecursive( array   & node , string   tagName , string   attName =null , string   attValue =null )

Traverses the XML tree from the currently focused node and attempts to match the given criteria.
public ___getCriteriaPathsRecursive( array   & $paths , array   & $node , string   $tagName , string   $attName =null , string   $attValue =null )

Traverses the XML tree from the currently focused node and attempts to match the given criteria.
public ___jinnConstruct( )

The constructor.
protected ___nodeAddChild( array   & $mommyNode , array   & $babyNode , mixed   & $index =null )

Inserts $babyNode into the XML structure as a child of $mommyNode.
protected boolean ___nodeDelete( array   & $node )

Removes the node from the XML structure and updates any references to ensure the node's entire hierarchy is removed.
protected ___nodeDeleteChildren( array   & $node )

Removes all the children of the given node from the XML structure.
protected ___nodeGetPath( array   & $node , boolean   $absolute =false )

Used to retrieve the targetting path for a given node.
protected ___nodeSetSubTree( array   & $node , array   & $subTree , JinnSimpleXml   & $xml , boolean   $isFirst )

Updates the given $node to have the same value, attributes, and hierarchical structure as the given $subTree.
protected ___setRoot( array   & $root )

This initializes the XML structure with a valid root.
protected bool allowCopies( )

Returns true to indicate to InterJinn that multiple instances of the service may exist.
public string asInnerString( int   $pretty =0 )

Positive values for the $pretty parameter indicate that the XML should be rendered in 'pretty' mode which generally makes it more readable.
public string asRawString( int   $pretty =0 )

Positive values for the $pretty parameter indicate that the XML should be rendered in 'pretty' mode which generally makes it more readable.
public string asString( int   $pretty =0 )

Positive values for the $pretty parameter indicate that the XML should be rendered in 'pretty' mode which generally makes it more readable.
public string asStringDebug( )

This can be used to debug problems with the XML lib.
protected asStringDebugPrimitive( mixed   $node , int   $depth =0 )

Recursive function for rendering the XML structure to a debugging output hierarchy.
protected asStringPrimitive( mixed   $node , int   $pretty =0 , int   $depth =0 )

Recursive function for rendering the XML structure to a standard textual representation.
protected mixed createPath( string   $path )

Creates nodes as necessary to fulfill the requested path criteria.
public delete( string   $path =null )

Removes the node at the requested path's target.
public deleteValue( string   $path =null )

Removes the node at the requested path's target.
public doPrint( int   $pretty =0 , string   $colour =null , string   $mode =null )

This function prints the results of getPrint() directly to standard output.
public doPrintDebug( string   $colour =null , string   $mode =null )

This function prints the results of getPrintDebug() directly to standard output.
public bool elementExists( string   $path )

Traverses the path and determines if it resolves to an actual element entry in the XML structure.
public bool focus( string   $path )

Attempts to change the focus to the given path.
public bool focusCriteria( string   tagName , string   attName =null , string   attValue =null )

Traverses the XML tree from the currently focused node and attempts to match the given criteria.
public bool focusId( string   id )

Changes the focus to the the node denoted by the given unique ID.
public bool focusParent( )

Changes the focus to the currently focused element's parent if it exists (root has no parent).
public focusReset( )

Resets the currently focused element back to the XML root.
public array getChildPaths( string   $path =null )

Returns an array of sub-paths that can be used to traverse the children of the target $path in order.
public array getChildren( string   $path =null )

Retrieved element names can be used as part of a path description to dynamically retrieve XML values.
public array getCriteriaPaths( string   $tagName , string   $attName =null , string   $attValue =null )

Traverses the XML tree from the currently focused node and attempts to match the given criteria.
public string getFocusName( )

Useful for determining the name of the currently focused node.
public string getFocusPath( )

Useful for determining the path to the currently focused node.
public array getIndexes( string   $path =null )

Returns an array of valid indexes for the path's target element.
public mixed getLiteral( string   $path =null , mixed   $dValue =null )

Returns the literal found at the requested path or the given default.
public string getParentName( )

Useful for determining the name of the currently focused node's parent.
protected array getPathTarget( string   $path )

Returns an associative array consisting of a target entry and an index entry.
protected mixed getPathTargetValue( string   $path )

Returns a reference to the actual value found at the target of the path.
public string getPrint( int   $pretty =0 , string   $colour =null , string   $mode =null )

Similar to the asString() method with the exception that the XML content is formatted with indentation denoting nesting levels of sub tags.
public string getPrintDebug( string   $colour =null , string   $mode =null )

Useful for debugging problems with the XML lib.
public string getRootName( )

Useful for determining the name of the XML tree's root node.
public mixed getString( string   $path =null , mixed   $dValue =null )

Returns a string representation of the value found at the requested path or the given default.
public mixed getSubTree( string   $path =null )

Returns the subtree found at the requested path.
public string getTagName( )

Useful for determining the name of the currently focused node.
public mixed getValue( string   $path =null )

Returns the value found at the requested path.
public bool parse( string   $xml , boolean   $trim =false )

The starting point for handling an XML document.
protected array parsePath( string   $path )

Many of the JinnSimpleXml methods utilizie this method to process requested paths.
public setRootName( string   $name )

Useful for changing the name of the tree's root node.
public integer setValue( string   $path , mixed   $value )

Sets a value at the given path's target.
public bool valueExists( string   $path )

Traverses the path and determines if it resolves to an actual entry in the XML structure.

Methods Inherited from JinnBaseClassReal
JinnBaseClassReal , ___jinnConstruct , applyCallbackRecursively , checkpoint , cleanPath , createClone , error , extractPairs , flattenPath , getCharset , getCodeRoot , getCompileVar , getCompileVars , getCoreRoot , getFilename , getHttpCookieVar , getHttpCookieVars , getHttpEnvVar , getHttpEnvVars , getHttpGetOrPostVar , getHttpGetVar , getHttpGetVars , getHttpLinkVar , getHttpLinkVars , getHttpPostFile , getHttpPostFiles , getHttpPostOrGetVar , getHttpPostVar , getHttpPostVars , getHttpServerVar , getHttpServerVars , getImageBase , getInterJinnVar , getInterJinnVars , getLibrary , getLibraryRef , getLoadInfo , getPageBase , getPageRoot , getPath , getPathPrefixType , getPrintData , getPrintFlat , getRunMode , getRunUid , getService , getServiceRef , getShellArg , getShellArgc , getShellArgv , getTime , getUniqueId , getVersion , getWebProfilingCategoryColour , getWebProfilingDataColour , getWebProfilingDefaultColour , halt , hashAppend , hashKeyDelete , hashKeyExists , hashKeyGet , hashKeyIsSet , hashKeySet , hashPathDelete , hashPathDeleteData , hashPathExists , hashPathGet , hashPathGetData , hashPathIsSet , hashPathSet , hashPathSetData , includeResource , isProfiling , libraryExists , localizeImage , localizePage , localizePath , makeRelativePath , markup , multilingualize , multilingualizeRef , normalizeArray , notice , overrideWarning , printData , printFlat , purgeOutputBuffers , redirect , refresh , serviceExists , setInterJinnVar , stripSlashes , stripSlashes_primitive , unwrapIfNecessary , unwrapObject , warning , wrapIfNecessary , wrapObject , xpathExists , xpathGet , xpathGetData , xpathIsSet  

Methods Inherited from JinnBaseClass
JinnBaseClass , ___jinnConstruct  

Methods Inherited from JinnBaseService
JinnBaseService , ___jinnConstruct , allowCopies , postLoadExecute  

Method Details
JinnSimpleXml

public JinnSimpleXml ( )

The constructor.

Source Code
function JinnSimpleXml()
{
   
$this->___jinnConstruct();
}

___createGroup

protected array ___createGroup ( )

Returns:
Returns an initialized XML grouping structure.

Groups are used to group together nodes with the same name into an indexed lookup map. The gorup stores the node ID and the name. This is necessary to target a specific node in a sequence of like-named nodes.

Source Code
function ___createGroup()
{
    return
        array
        (
           
'gid'   => ++$this->maxGid,     // ID of this group.
           
'name'  => null,                // Name of group (tag name).
           
'nids'  => array(),             // Array of nodes: idx => nid.
           
'midx'  => 0,                   // Max node idx within group.
       
);
}

___createNode

protected array ___createNode ( )

Returns:
Returns an initialized XML node structure.

Used to construct the node tree. The method will create a blank node structure and automatically assign it the next available node ID. The node is not associated witht he XML structure by this method.

Source Code
function ___createNode()
{
    return
        array
        (
           
'nid'   => ++$this->maxNid,     // ID of node.
           
'pid'   => 0,                   // ID of parent node.
           
'gid'   => 0,                   // ID of grouping container.
           
'idx'   => 0,                   // ID of node within group.
           
'name'  => null,                // Tag name.
           
'text'  => null,                // Textual content of the tag.
           
'atts'  => array(),             // Array of attributes/values.
           
'nids'  => array(),             // Array of child node IDs.
           
'gids'  => array(),             // Array of child gids by tag.
       
);
}

___focusCriteriaRecursive

public bool ___focusCriteriaRecursive
(
     array      & node ,
     string      tagName ,
     string      attName = null ,
     string      attValue = null
)


Parameters:
node -