Class XmlNewGroupElement
java.lang.Object
com.aquima.interactions.foundation.xml.generation.XmlNewGroupElement
- All Implemented Interfaces:
IXmlElement
,Serializable
XML element that may be used during generation to combine several XML element. This element will be discarded once
added to a (parent) node, and instead all its children will be added to the parent node.
- Since:
- 6.4
- Author:
- O. Kerpershoek
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddChild
(IXmlElement child) Add a child element.addChildCopy
(IXmlElement child) Add a child element.void
addChildren
(IXmlElement[] children) Adds the children array to the element, it's an easy method for adding all children seperately.void
addSibling
(IXmlElement child, IXmlElement newSibling, boolean before) Add a sibling child next to a given existing child.boolean
check if node exists in our tree - used for cycle detection.findAncestor
(String name) Find the XMLNewElement that is an ancestor of the current XMLNewElement, with the specified name.findChildren
(String tagname) Find the elements that occurs as child (only one level deep).findFirstChild
(String tagname) Find the first direct child with the given tag name, throws exception if it's not found.Get the first sub-element with a certain XML tag name.Make a list of all XmlNewElement elements with a certain XML tag name, recursively.getAttribute
(String name) Get the value of an attribute of this element.String[]
Get all attribute names of this element.getAttributeSafe
(String name) Get the value of an attribute of this element.Get all attributes of this element, as an ATTRNAME-to-VALUE mapping.Return a list of all children of this element (only one level deep).Returns the first child of this element (only one level deep).Returns the first element child of this element (only one level deep).getName()
The name of the element (usually the XML tag).Return the node immediately following this node.returns the parent node, raises XmlException if there is no parent.returns the parent node, or null if there is no parent.getValue()
The text 'value' of the element -- easy shortcut to get tag values.boolean
Shortcut method to quickly see if there are any attributes.boolean
isCData()
This method returns a boolean indicating if the value will be wrapped in a CDATA block.remove all child nodes.removeAttribute
(String name) This method removes the attribute with the specified name.void
removeChild
(IXmlElement childNode) remove a child node.void
replaceChild
(IXmlElement oldChild, IXmlElement newChild) replace a child with a new child.setAttribute
(String name, String stringValue) Set an attribute for this element, name=value.void
setCData
(boolean enable) Enable (or disable) CDATA representation.void
Change the tag name of an element.void
setParent
(IXmlElement parent) internal: set the parent of this node.void
setValue
(boolean booleanValue) change the value to a new boolean (true/false).void
Change the value.void
setValue
(double doubleValue) change the value to a new double (default number of digits after decimal point).void
setValue
(double doubleValue, int digits) change the value to a new double (with specified number of digits after the decimal point).void
setValue
(int integerValue) change the value to a new int.void
setValue
(long longValue) change the value to a new long.void
setValue
(XmlGenerator gen) change the value to be another full XML document (not indented).void
Change the text value of an element.void
change the value to a new Date (XSD/ISO notation: YYYY-MM-DDTHH:mm:ss).void
change the value to a new Date (XSD/ISO notation: YYYY-MM-DDTHH:mm:ss) with or without time.Easy way to create an XML string for this element and the children.toXmlFragment
(boolean useIndentation) Easy way to create an XML string for this element and the children.void
toXmlFragment
(boolean useIndentation, boolean sortAttributes, int level, StringBuffer str) Recursive conversion to an XML document.void
toXmlFragment
(int level, StringBuffer str) Recursive conversion to an XML document.
-
Constructor Details
-
XmlNewGroupElement
public XmlNewGroupElement()
-
-
Method Details
-
getParentSafe
Description copied from interface:IXmlElement
returns the parent node, or null if there is no parent.- Specified by:
getParentSafe
in interfaceIXmlElement
- Returns:
- The XML element of the parent node.
-
replaceChild
Description copied from interface:IXmlElement
replace a child with a new child.- Specified by:
replaceChild
in interfaceIXmlElement
- Parameters:
oldChild
- child node to replacenewChild
- child node to replace with
-
addChild
Description copied from interface:IXmlElement
Add a child element. Only useful if the element has not yet been added as a child.- Specified by:
addChild
in interfaceIXmlElement
- Parameters:
child
- the new node to add as a child node (a reference will be added - any changes made to the child after it was added will be performed on the child in the XML structure too) Beware of Circular References!!!- Returns:
- the newly added child element
-
addChildren
Description copied from interface:IXmlElement
Adds the children array to the element, it's an easy method for adding all children seperately. If the array is empty no childs are added.- Specified by:
addChildren
in interfaceIXmlElement
- Parameters:
children
- The children array.
-
addChildCopy
Description copied from interface:IXmlElement
Add a child element. Only useful if the element has not yet been added as a child. Because copies are made, this method is slower (but safer) than the other add method.- Specified by:
addChildCopy
in interfaceIXmlElement
- Parameters:
child
- the new node to add as a child node (a replica will be added - any changes made to the child after it was added are useless, unless you add the same object again).- Returns:
- the newly added copy of the child element
- See Also:
-
removeChild
Description copied from interface:IXmlElement
remove a child node.- Specified by:
removeChild
in interfaceIXmlElement
- Parameters:
childNode
- node to remove
-
removeAllChildren
Description copied from interface:IXmlElement
remove all child nodes.- Specified by:
removeAllChildren
in interfaceIXmlElement
- Returns:
- Array containing the children that were removed.
-
addSibling
Description copied from interface:IXmlElement
Add a sibling child next to a given existing child.- Specified by:
addSibling
in interfaceIXmlElement
- Parameters:
child
- existing child node to add a new node next tonewSibling
- new node to addbefore
- set to true if you want to insert before existing child, otherwise the new sibling is inserted after it
-
getChildren
Description copied from interface:IXmlElement
Return a list of all children of this element (only one level deep). This includes comment nodes, entity nodes, TEXT nodes etc. !!!!!- Specified by:
getChildren
in interfaceIXmlElement
- Returns:
- the list of XmlNode children for this element (empty List when there are no children)
-
containsNode
Description copied from interface:IXmlElement
check if node exists in our tree - used for cycle detection.- Specified by:
containsNode
in interfaceIXmlElement
- Parameters:
n
- The element that should be checked.- Returns:
- boolean indicating if the element is present as a child element.
-
findTag
Get the first sub-element with a certain XML tag name.- Specified by:
findTag
in interfaceIXmlElement
- Parameters:
tagname
- the name of the tag- Returns:
- the first sub-element with the given tagname
- Throws:
XmlException
- if no tag was found
-
findChildren
Description copied from interface:IXmlElement
Find the elements that occurs as child (only one level deep). Returns empty list if no children are found.- Specified by:
findChildren
in interfaceIXmlElement
- Parameters:
tagname
- The tag name for which all children are requested.- Returns:
- The list of children matching the spacified tag name.
-
findTags
Description copied from interface:IXmlElement
Make a list of all XmlNewElement elements with a certain XML tag name, recursively. The list is constructed in preorder document traversal (depth-first).- Specified by:
findTags
in interfaceIXmlElement
- Parameters:
tagname
- the name of the tags you seek- Returns:
- a List containing all XmlNewElement with the tag name. It will be an empty list if no tags are found.
-
findFirstChild
Find the first direct child with the given tag name, throws exception if it's not found.- Specified by:
findFirstChild
in interfaceIXmlElement
- Parameters:
tagname
- The tag name of the child element that should be returned.- Returns:
- The child element for the specified tag name.
- Throws:
XmlException
- This exception is thrown when no element with the specified tag-name could be found.
-
getFirstElement
Description copied from interface:IXmlElement
Returns the first element child of this element (only one level deep). This will skip comment nodes, entity nodes, #TEXT nodes etc.- Specified by:
getFirstElement
in interfaceIXmlElement
- Returns:
- the first element child of this element
-
getFirstChild
Returns the first child of this element (only one level deep). This may be a comment node, entity node, #TEXT node etc. !!!!!- Specified by:
getFirstChild
in interfaceIXmlElement
- Returns:
- the first child node of this element
- Throws:
XmlException
- if this element has no child nodes
-
findAncestor
Description copied from interface:IXmlElement
Find the XMLNewElement that is an ancestor of the current XMLNewElement, with the specified name. Throws exception if the ancestor is not found.- Specified by:
findAncestor
in interfaceIXmlElement
- Parameters:
name
- The tag name of the ancestor that is requested.- Returns:
- The ancestor with the specified tag name.
-
getAttribute
Description copied from interface:IXmlElement
Get the value of an attribute of this element.- Specified by:
getAttribute
in interfaceIXmlElement
- Parameters:
name
- the attribute name to get the value of.- Returns:
- the value of the attribute
- See Also:
-
getAttributeSafe
Description copied from interface:IXmlElement
Get the value of an attribute of this element.- Specified by:
getAttributeSafe
in interfaceIXmlElement
- Parameters:
name
- the attribute name to get the value of.- Returns:
- the value of the attribute (String), or null if the attribute doesn't exist.
- See Also:
-
getAttributes
Description copied from interface:IXmlElement
Get all attribute names of this element. If there are no attributes, returns an empty array.- Specified by:
getAttributes
in interfaceIXmlElement
- Returns:
- Array containing all the attribute names of this element.
- See Also:
-
getAttributesMap
Description copied from interface:IXmlElement
Get all attributes of this element, as an ATTRNAME-to-VALUE mapping. If there are no attributes, returns an empty Map.- Specified by:
getAttributesMap
in interfaceIXmlElement
- Returns:
- Map containing all the attribute names and values.
- See Also:
-
getName
Description copied from interface:IXmlElement
The name of the element (usually the XML tag).- Specified by:
getName
in interfaceIXmlElement
- Returns:
- The name of the xml element.
-
setName
Description copied from interface:IXmlElement
Change the tag name of an element.- Name can contain letters, numbers, and other characters
- Name cannot start with a number or punctuation character
- Name cannot start with the letters xml (or XML, or Xml, etc)
- Name cannot contain spaces, <, >, ", ' or &
- Specified by:
setName
in interfaceIXmlElement
- Parameters:
name
- the name of the element.
-
getParent
Description copied from interface:IXmlElement
returns the parent node, raises XmlException if there is no parent.- Specified by:
getParent
in interfaceIXmlElement
- Returns:
- The XML element of the parent node.
-
setParent
Description copied from interface:IXmlElement
internal: set the parent of this node.- Specified by:
setParent
in interfaceIXmlElement
- Parameters:
parent
- The new parent of the element.
-
getValue
Description copied from interface:IXmlElement
The text 'value' of the element -- easy shortcut to get tag values.- Specified by:
getValue
in interfaceIXmlElement
- Returns:
- The text value of the element.
-
hasAttributes
public boolean hasAttributes()Description copied from interface:IXmlElement
Shortcut method to quickly see if there are any attributes.- Specified by:
hasAttributes
in interfaceIXmlElement
- Returns:
- Boolean indicating if this element has any attributes.
-
isCData
public boolean isCData()Description copied from interface:IXmlElement
This method returns a boolean indicating if the value will be wrapped in a CDATA block.- Specified by:
isCData
in interfaceIXmlElement
- Returns:
- Boolean indicating if the value will be wrapped in a CDATA block
-
setCData
public void setCData(boolean enable) Description copied from interface:IXmlElement
Enable (or disable) CDATA representation. CDATA mode outputs unescaped data in <![CDATA[ ... ]]> delimiters. Note that this has no effect on parsing because they will process the CDATA block automatically. You only change the output representation of this element's value.- Specified by:
setCData
in interfaceIXmlElement
- Parameters:
enable
- enable CDATA representation? true, false=disable.
-
removeAttribute
Description copied from interface:IXmlElement
This method removes the attribute with the specified name. When there was no attribute specified for the given name, this method has no effect. The attribute name is case sensitive.- Specified by:
removeAttribute
in interfaceIXmlElement
- Parameters:
name
- The name of the attribute that should be removed.- Returns:
- The previous value of the attribute that has been removed.
-
setAttribute
Description copied from interface:IXmlElement
Set an attribute for this element, name=value. Only useful if the element has not yet been added as a child- Name can contain letters, numbers, and other characters
- Name cannot contain spaces, <, >, ", ' or &
- Value cannot be null
- Specified by:
setAttribute
in interfaceIXmlElement
- Parameters:
name
- The name of the attribute that should be set.stringValue
- The value of the attribute.- Returns:
- The previous value of the attribute, may be null.
-
setValue
public void setValue(boolean booleanValue) Description copied from interface:IXmlElement
change the value to a new boolean (true/false).- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
booleanValue
- The new boolean value.
-
setValue
Description copied from interface:IXmlElement
change the value to a new Date (XSD/ISO notation: YYYY-MM-DDTHH:mm:ss).- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
dateValue
- The new date value.
-
setValue
public void setValue(double doubleValue) Description copied from interface:IXmlElement
change the value to a new double (default number of digits after decimal point).- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
doubleValue
- The new double value.
-
setValue
public void setValue(int integerValue) Description copied from interface:IXmlElement
change the value to a new int.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
integerValue
- The new integer value.
-
setValue
public void setValue(long longValue) Description copied from interface:IXmlElement
change the value to a new long.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
longValue
- The new long value.
-
setValue
Description copied from interface:IXmlElement
Change the text value of an element. Be careful if your node has already been added to a tree.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
stringValue
- The new value for the element.
-
setValue
Description copied from interface:IXmlElement
change the value to be another full XML document (not indented). You might want to consider setting CDATA for this element if you use this.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
gen
- The XML element that should entirely be included as value.
-
setValue
Description copied from interface:IXmlElement
Change the value. Only useful if the element has not yet been added as a child.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
rawValue
- the raw byte array of the new valueencoding
- the character encoding used for the byte array
-
setValue
Description copied from interface:IXmlElement
change the value to a new Date (XSD/ISO notation: YYYY-MM-DDTHH:mm:ss) with or without time.- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
dateValue
- The new date value.withTime
- boolean indicating if the time should be included in the value.
-
setValue
public void setValue(double doubleValue, int digits) Description copied from interface:IXmlElement
change the value to a new double (with specified number of digits after the decimal point).- Specified by:
setValue
in interfaceIXmlElement
- Parameters:
doubleValue
- The new double value.digits
- The number of digits that should be included.
-
toXmlFragment
Description copied from interface:IXmlElement
Easy way to create an XML string for this element and the children. Indent starts at 0. The toXMLfragment method operating on a StringBuffer is faster and better suited when creating only a part of a larger document. This method returns a string and was designed to get the "final" representation. It uses whitespace indentation for pretty printing.- Specified by:
toXmlFragment
in interfaceIXmlElement
- Returns:
- String containing the XML of this element and children.
-
toXmlFragment
Description copied from interface:IXmlElement
Easy way to create an XML string for this element and the children. Indent starts at 0. The toXMLfragment method operating on a StringBuffer is faster and better suited when creating only a part of a larger document. This method returns a string and was designed to get the "final" representation.- Specified by:
toXmlFragment
in interfaceIXmlElement
- Parameters:
useIndentation
- true to use whitespace indentation for pretty printing, false to avoid any whitespace between XML elements- Returns:
- String containing the XML of this element and children.
-
toXmlFragment
public void toXmlFragment(boolean useIndentation, boolean sortAttributes, int level, StringBuffer str) Description copied from interface:IXmlElement
Recursive conversion to an XML document. XML problem chars will be escaped (",<,>, etc). The XML code is appended to a stringbuffer. It uses indentation for pretty printing. Indentation starts at 0.- Specified by:
toXmlFragment
in interfaceIXmlElement
- Parameters:
useIndentation
- true to use whitespace indentation for pretty printing, false to avoid any whitespace between XML elementssortAttributes
- true to use sort the attributes by name in alphabetic order.level
- indentation level (tabs), start with 0 (unused if useIndentation is false)str
- existing StringBuffer to append into
-
toXmlFragment
Description copied from interface:IXmlElement
Recursive conversion to an XML document. XML problem chars will be escaped (",<,>, etc). The XML code is appended to a stringbuffer. It uses indentation for pretty printing.- Specified by:
toXmlFragment
in interfaceIXmlElement
- Parameters:
level
- indentation level (tabs), start with 0str
- existing StringBuffer to append into
-
getNextSibling
Description copied from interface:IXmlElement
Return the node immediately following this node. If there is no such node, this returns null. This includes comment nodes, entity nodes, TEXT nodes etc. !!!!!- Specified by:
getNextSibling
in interfaceIXmlElement
- Returns:
- the node immediately following this node. If there is no such node, this returns null.
-