com.tle.common.scripting.types
Interface XmlScriptType
Declaration: public interface XmlScriptType extends java.io.Serializable
All Superinterfaces: java.io.Serializable

 

Object for XML manipulation in scripts. Generally referred to as 'xml' in scripts, also available as 'newxml' in New Version scripts and 'attributes' in Advanced Scripting wizard controls. Note that all XPath parameters are not true XPaths and are limited to simple node/attribute selection and node indexes. E.g. /xml/test/node[2]/@attribute is as complex as it will get.

 

 

Methods Summary
abstract void add(java.lang.String xpath, java.lang.String value)
    
Add a new node and set its value.
abstract void append(java.lang.String xpath, XmlScriptType documentToAppend)
    
Appends another XML document at the given XPath.
abstract void appendChildren(java.lang.String xpath, XmlScriptType documentToAppend)
    
Appends the first-level of children from an XML document at the given XPath.
abstract java.lang.String asString()
    
abstract void clear()
    
Deletes all nodes and changes the XML to <xml/>
abstract boolean contains(java.lang.String xpath, java.lang.String value)
    
Find out if any value of the nodes with a given XPath match a certain value.
abstract void copy(java.lang.String srcXpath, java.lang.String destXpath)
    
Copy the text value of the node found at srcXpath into the text value of the node found at destXpath.
abstract int count(java.lang.String xpath)
    
Returns the number of matching XPaths.
abstract XmlScriptType createSubtree(java.lang.String xpath)
    
Creates a subtree rooted at XPath.
abstract void deleteAll(java.lang.String xpath)
    
Deletes all nodes matching the XPath
abstract void deleteNode(java.lang.String xpath)
    
Deletes the first node matching the XPath
abstract void deleteSubtree(XmlScriptType subtree)
    
Removes the subtree from the xml.
abstract boolean exists(java.lang.String xpath)
    
Determine if any node exists at the following XPath.
abstract XmlScriptType findForId(java.lang.String id)
    
Returns an XmlScriptType object for the sub-tree that is rooted at the node with an "id" attribute value matching the parameter.
abstract java.lang.String get(java.lang.String xpath)
    
Get the text value of a node using an XPath like syntax.
abstract java.lang.String[] getAll(java.lang.String xpath)
    
Returns all node text values for a given XPath.
abstract XmlScriptType[] getAllSubtrees(java.lang.String xpath)
    
A more useful alternative to getAll.
abstract XmlScriptType getOrCreateSubtree(java.lang.String xpath)
    
Same as getSubtree(String) only that if there is no node matching XPath, a new sub-tree is created.
abstract XmlScriptType getSubtree(java.lang.String xpath)
    
Returns an XmlScriptType object for the sub-tree that is rooted at the first node matching XPath.
abstract java.util.List<java.lang.String> list(java.lang.String xpath)
    
Same as getAll(String) but returns a java.util.List object
abstract void set(java.lang.String xpath, java.lang.String value)
    
Set the text value of a node.

 

 

 

 

get

 

public abstract java.lang.String get( java.lang.String xpath)

 

Get the text value of a node using an XPath like syntax. If there is more than one node with that XPath, it will return the value in the first one. If the node cannot be found, a blank string will be returned. You can use exists(String) to determine if a node exists.

 

Parameters:
xpath-
The XPath to get the value from
Returns:
The value from the XML document

 

 

 

set

 

public abstract void set( java.lang.String xpath,
java.lang.String value)

 

Set the text value of a node. Node will be created if there is none found at XPath

 

Parameters:
xpath-
The XPath to the node.
value-
The new text value of the node.

 

 

 

contains

 

public abstract boolean contains( java.lang.String xpath,
java.lang.String value)

 

Find out if any value of the nodes with a given XPath match a certain value.

 

Parameters:
xpath-
The XPath to the node(s)
value-
The value to check for
Returns:
true if the value is found

 

 

 

exists

 

public abstract boolean exists( java.lang.String xpath)

 

Determine if any node exists at the following XPath.

 

Parameters:
xpath-
The XPath to the node
Returns:
true if any node can be found

 

 

 

count

 

public abstract int count( java.lang.String xpath)

 

Returns the number of matching XPaths.

 

Parameters:
xpath-
The XPath to the node(s).
Returns:
the number of matching XPaths.

 

 

 

getAll

 

public abstract java.lang.String[] getAll( java.lang.String xpath)

 

Returns all node text values for a given XPath.

 

Parameters:
xpath-
The XPath to the node(s)
Returns:
An array of all the text values of the matching nodes

 

 

 

list

 

public abstract java.util.List<java.lang.String> list( java.lang.String xpath)

 

Same as getAll(String) but returns a java.util.List object

 

Parameters:
xpath-
The XPath to the node(s)
Returns:
A list of all the text values of the matching nodes

 

 

 

getAllSubtrees

 

public abstract XmlScriptType[] getAllSubtrees( java.lang.String xpath)

 

A more useful alternative to getAll.

 

Parameters:
xpath-
The XPath to the sub-tree root node(s)
Returns:
An array of XmlScriptType which are the sub-trees found at XPath

 

 

 

add

 

public abstract void add( java.lang.String xpath,
java.lang.String value)

 

Add a new node and set its value. This will always add a new node, even if there is already a node at the given XPath.

 

Parameters:
xpath-
The XPath to the new node
value-
The text value of the new node

 

 

 

copy

 

public abstract void copy( java.lang.String srcXpath,
java.lang.String destXpath)

 

Copy the text value of the node found at srcXpath into the text value of the node found at destXpath.

 

Parameters:
srcXpath-
The XPath to the source node
destXpath-
The XPath to the destination node

 

 

 

deleteNode

 

public abstract void deleteNode( java.lang.String xpath)

 

Deletes the first node matching the XPath

 

Parameters:
xpath-
The XPath of the node to delete

 

 

 

deleteAll

 

public abstract void deleteAll( java.lang.String xpath)

 

Deletes all nodes matching the XPath

 

Parameters:
xpath-
The XPath of the nodes to delete.

 

 

 

clear

 

public abstract void clear( )

 

Deletes all nodes and changes the XML to <xml/>

 

 

 

getSubtree

 

public abstract XmlScriptType getSubtree( java.lang.String xpath)

 

Returns an XmlScriptType object for the sub-tree that is rooted at the first node matching XPath. If there is no node at XPath, then null is returned. This sub-tree is still linked to the original tree, any changes made to the sub-tree will be reflected in the original.

 

Parameters:
xpath-
The XPath of the sub-tree root node.
Returns:
The sub-tree found at XPath.

 

 

 

getOrCreateSubtree

 

public abstract XmlScriptType getOrCreateSubtree( java.lang.String xpath)

 

Same as getSubtree(String) only that if there is no node matching XPath, a new sub-tree is created.

 

Parameters:
xpath-
The XPath of the sub-tree root node.
Returns:
The sub-tree found at XPath, or a brand new sub-tree rooted at XPath.

 

 

 

createSubtree

 

public abstract XmlScriptType createSubtree( java.lang.String xpath)

 

Creates a subtree rooted at XPath. This will always create a subtree, regardless of whether there is a node at XPath already.

 

Parameters:
xpath-
The XPath of the sub-tree root node.
Returns:
The new sub-tree rooted at XPath.

 

 

 

deleteSubtree

 

public abstract void deleteSubtree( XmlScriptType subtree)

 

Removes the subtree from the xml.

 

Parameters:
subtree-
The tree to remove from the xml (obtained via getSubtree, getOrCreateSubtree, createSubtree or getAllSubtrees)

 

 

 

append

 

public abstract void append( java.lang.String xpath,
XmlScriptType documentToAppend)

 

Appends another XML document at the given XPath.

 

Parameters:
xpath-
The XPath to insert the new document into.
documentToAppend-
The XML document to insert.

 

 

 

appendChildren

 

public abstract void appendChildren( java.lang.String xpath,
XmlScriptType documentToAppend)

 

Appends the first-level of children from an XML document at the given XPath. This works the same as append(String, XmlScriptType), but does not include the root element of the document.

 

Parameters:
xpath-
The XPath to insert the new document into.
documentToAppend-
The XML document whose first-level children will be inserted from.

 

 

 

findForId

 

public abstract XmlScriptType findForId( java.lang.String id)

 

Returns an XmlScriptType object for the sub-tree that is rooted at the node with an "id" attribute value matching the parameter. If there is no node at XPath, then null is returned. This sub-tree is still linked to the original tree, any changes made to the sub-tree will be reflected in the original.

 

Parameters:
id-
The ID of the sub-tree root node.
Returns:
The sub-tree found for ID.

 

 

 

asString

 

public abstract java.lang.String asString( )

 

Returns:
A string representation of the XML