net.sf.nxqd
Class NxqdModify

java.lang.Object
  extended by net.sf.nxqd.NxqdConsumer
      extended by net.sf.nxqd.NxqdModify

public class NxqdModify
extends NxqdConsumer

The class NxqdModify is the context within which a set of one or more documents specified by an XQuery query can be modified in place. The modification is performed using an NxqdModify object, and a series of methods off that object that identify how the document is to be modified. Using these methods, the modification steps are identified. When the object is executed, these steps are performed in the order that they were specified.

Version:
1.0
Author:
webhiker

Method Summary
 void addAppendStep(NxqdQueryExpression selectionExpr, int type, String name, String content)
          Appends the provided data to the selected node's child notes.
 void addAppendStep(NxqdQueryExpression selectionExpr, int type, String name, String content, int location)
          Appends the provided data to the selected node's child notes.
 void addInsertAfterStep(NxqdQueryExpression selectionExpr, int type, String name, String content)
          Inserts the provided data into the document after the selected node.
 void addInsertBeforeStep(NxqdQueryExpression selectionExpr, int type, String name, String content)
          Inserts the provided data into the document before the selected node, as a previous sibling.
 void addRemoveStep(NxqdQueryExpression selectionExpr)
          Removes the node targeted by the selection expression.
 void addRenameStep(NxqdQueryExpression selectionExpr, String newName)
          Renames an element node, attribute node, or processing instruction.
 void addUpdateStep(NxqdQueryExpression selectionExpr, String content)
          Replaces the targeted node's content with text.
 
Methods inherited from class net.sf.nxqd.NxqdConsumer
getNxqdManager, setNxqdManager
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addAppendStep

public void addAppendStep(NxqdQueryExpression selectionExpr,
                          int type,
                          String name,
                          String content)
                   throws NxqdException
Appends the provided data to the selected node's child notes. If the operation's target is an attribute node or the document root node, an exception is thrown at modification execution time. If the content to be added is an attribute, the content is added to the targeted node's attribute list. If the content to add is an element node, text, comment or processing instruction, its content is added immediately after the targeted node's last child node, unless the location parameter is specified. Documents resulting from this modification must be well-formed XML or an exception is thrown at modification execution time, if the documents affected are written back to their respective containers.

Parameters:
selectionExpr - a NxqdQueryExpression The XQuery expression used to target the location in the document where the modification is to be performed. Use NxqdManager.prepare(...) to create the NxqdQueryExpression. The query that you provide must target zero or more nodes, or an exception is thrown. If zero nodes are selected, no modifications are performed when execute(...) is called.
type - an int The type of information to be inserted. The value provided here determines whether the name or content parameter is required. Valid values are: Element, Attribute, Text, ProcessingInstruction or Comment.
name - a String The name of the node, attribute, or processing instruction to insert. This parameter is ignored if type is NxqdModify.Text
content - a String value
Throws:
NxqdException - if an error occurs

addAppendStep

public void addAppendStep(NxqdQueryExpression selectionExpr,
                          int type,
                          String name,
                          String content,
                          int location)
                   throws NxqdException
Appends the provided data to the selected node's child notes. If the operation's target is an attribute node or the document root node, an exception is thrown at modification execution time. If the content to be added is an attribute, the content is added to the targeted node's attribute list. If the content to add is an element node, text, comment or processing instruction, its content is added immediately after the targeted node's last child node, unless the location parameter is specified. Documents resulting from this modification must be well-formed XML or an exception is thrown at modification execution time, if the documents affected are written back to their respective containers.

Parameters:
selectionExpr - a NxqdQueryExpression The XQuery expression used to target the location in the document where the modification is to be performed. Use NxqdManager.prepare(...) to create the NxqdQueryExpression. The query that you provide must target zero or more nodes, or an exception is thrown. If zero nodes are selected, no modifications are performed when execute(...) is called.
type - an int The type of information to be inserted. The value provided here determines whether the name or content parameter is required. Valid values are: Element, Attribute, Text, ProcessingInstruction or Comment.
name - a String The name of the node, attribute, or processing instruction to insert. This parameter is ignored if type is NxqdModify.Text
content - a String value
location - an int Identifies the position in the child node list where the provided content is to be inserted. For example, if location is 3, and the target element has at least 3 child nodes, the new content will become the 3rd child of the target node. If this parameter is a negative number, or if this parameter contains a value that is larger than the number of child nodes, then the new node will be the last child node.
Throws:
NxqdException - if an error occurs

addInsertAfterStep

public void addInsertAfterStep(NxqdQueryExpression selectionExpr,
                               int type,
                               String name,
                               String content)
                        throws NxqdException
Inserts the provided data into the document after the selected node. If the operation's target is an attribute node or the document root node, an exception is thrown at modification execution time. If the content to be added is an attribute, the content is added to the targeted node's parent node. For any other type of content, the content is inserted into the document immediately after the targeted node's end tag, as its next sibling. Documents resulting from this modification must be well-formed XML or an exception is thrown at modification execution time, if the documents affected are written back to their respective containers.

Parameters:
selectionExpr - a NxqdQueryExpression value. The XQuery expression used to target the location in the document where the modification is to be performed.
type - an int value. The type of information to be inserted. The value provided here determines whether the name or content parameter is required. Valid values are: Element, Attribute, Text, ProcessingInstruction or Comment.
name - a String value. The name of the node, attribute, or processing instruction to insert. This parameter is ignored if type is NxqdModify.Text or NxqdModify.Comment.
content - a String value
Throws:
NxqdException - if an error occurs

addInsertBeforeStep

public void addInsertBeforeStep(NxqdQueryExpression selectionExpr,
                                int type,
                                String name,
                                String content)
                         throws NxqdException
Inserts the provided data into the document before the selected node, as a previous sibling. If the operation's target is an attribute node or the document root node, an exception is thrown at modification execution time. If the content to be added is an attribute, the content is added to the targeted node's parent node. For any other type of content, the content is inserted into the document immediately before the targeted node's start tag. Documents resulting from this modification must be well-formed XML or an exception is thrown at modification execution time, if the documents affected are written back to their respective containers.

Parameters:
selectionExpr - a NxqdQueryExpression value. The XQuery expression used to target the location in the document where the modification is to be performed.
type - an int value. The type of information to be inserted. The value provided here determines whether the name or content parameter is required. Valid values are: Element, Attribute, Text, ProcessingInstruction or Comment.
name - a String value. The name of the node, attribute, or processing instruction to insert. This parameter is ignored if type is NxqdModify.Text or NxqdModify.Comment.
content - a String value
Throws:
NxqdException

addRemoveStep

public void addRemoveStep(NxqdQueryExpression selectionExpr)
                   throws NxqdException
Removes the node targeted by the selection expression. If the operation's target is the document root node an exception is thrown at modification execution time.

Parameters:
selectionExpr - a NxqdQueryExpression value
Throws:
NxqdException - if an error occurs

addRenameStep

public void addRenameStep(NxqdQueryExpression selectionExpr,
                          String newName)
                   throws NxqdException
Renames an element node, attribute node, or processing instruction. If the document content targeted by selectionExpr is any other type of content, an exception is thrown at modification execution time.

Parameters:
selectionExpr - a NxqdQueryExpression value
newName - a String value
Throws:
NxqdException - if an error occurs

addUpdateStep

public void addUpdateStep(NxqdQueryExpression selectionExpr,
                          String content)
                   throws NxqdException
Replaces the targeted node's content with text. If the targeted node is an element node, all of the element node's children and text nodes are replaced with text. If the targeted node is an attribute node, the attribute's value is replaced by text. The purpose of this interface is primarily to replace text content. Note that text is treated as a text node. If it contains mark-up, that mark-up is escaped to make it legal text. Documents resulting from this modification must be well-formed XML or an exception is thrown at modification execution time, if the documents affected are written back to their respective containers.

Parameters:
selectionExpr - a NxqdQueryExpression value
content - a String value
Throws:
NxqdException - if an error occurs


Copyright © 2005-2006 nxqd. All Rights Reserved.