|
interJinn Class JinnSimpleXml (EXPERIMENTAL) |
public
class
JinnSimpleXml
$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 JinnBaseClass |
| JinnBaseClass , ___jinnConstruct |
| Methods Inherited from JinnBaseService |
| JinnBaseService , ___jinnConstruct , allowCopies , postLoadExecute |