Class SpinXmlElement

Direct Known Subclasses:
DomXmlElement

public abstract class SpinXmlElement extends SpinXmlNode<SpinXmlElement>
An element in a tree-oriented XML data format.
Author:
Sebastian Menski, Daniel Meyer
  • Constructor Details

    • SpinXmlElement

      public SpinXmlElement()
  • Method Details

    • hasAttr

      public abstract boolean hasAttr(String attributeName)
      Checks whether this element has a attribute with an empty namespace and the given name.
      Parameters:
      attributeName - the name of the attribute
      Returns:
      true if the element has an attribute with this name under the local namespace, false otherwise
      Throws:
      IllegalArgumentException - if the attributeName is null
    • attr

      public abstract SpinXmlAttribute attr(String attributeName)
      Returns the wrapped attribute for an empty namespace and the given name.
      Parameters:
      attributeName - the name of the attribute
      Returns:
      the wrapped attribute
      Throws:
      IllegalArgumentException - if the attributeName is null
      SpinXmlAttributeException - if the attribute is not found
    • attr

      public abstract SpinXmlElement attr(String attributeName, String value)
      Sets the attribute value in the local namespace of this element.
      Parameters:
      attributeName - the name of the attribute
      value - the value to set
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the attributeName or value is null
    • removeAttr

      public abstract SpinXmlElement removeAttr(String attributeName)
      Removes the attribute with an empty namespace.
      Parameters:
      attributeName - the name of the attribute
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the attributeName is null
    • hasAttrNs

      public abstract boolean hasAttrNs(String namespace, String attributeName)
      Checks whether this element has a attribute with the given namespace and name.
      Parameters:
      namespace - the namespace of the attribute
      attributeName - the name of the attribute
      Returns:
      true if the element has an attribute with this name under given namespace, false otherwise
      Throws:
      IllegalArgumentException - if the attributeName is null
    • attrNs

      public abstract SpinXmlAttribute attrNs(String namespace, String attributeName)
      Returns the wrapped attribute for the given namespace and name.
      Parameters:
      namespace - the namespace of the attribute
      attributeName - the name of the attribute
      Returns:
      the wrapped attribute
      Throws:
      IllegalArgumentException - if attributeName or value is null
      SpinXmlElementImplementationException - if the attribute cannot be set in the underlying implementation
    • attrNs

      public abstract SpinXmlElement attrNs(String namespace, String attributeName, String value)
      Sets the attribute value in the given namespace.
      Parameters:
      namespace - the namespace of the attribute
      attributeName - the name of the attribute
      value - the value to set
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if attributeName or value is null
      SpinXmlElementImplementationException - if the attribute cannot be set in the underlying implementation
    • removeAttrNs

      public abstract SpinXmlElement removeAttrNs(String namespace, String attributeName)
      Removes the attribute under the given namespace.
      Parameters:
      namespace - the namespace of the attribute
      attributeName - the name of the attribute
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the attributeName is null
    • attrs

      public abstract SpinList<SpinXmlAttribute> attrs()
      Returns all wrapped attributes of this element.
      Returns:
      the wrapped attributes or an empty list of no attributes are found
    • attrs

      public abstract SpinList<SpinXmlAttribute> attrs(String namespace)
      Returns all wrapped attributes for the given namespace.
      Parameters:
      namespace - the namespace of the attributes
      Returns:
      the wrapped attributes or an empty list of no attributes are found
    • attrNames

      public abstract List<String> attrNames()
      Returns all names of the attributes of this element.
      Returns:
      the names of the attributes
    • attrNames

      public abstract List<String> attrNames(String namespace)
      Returns all names of the attributes in the given namespace.
      Returns:
      the names of the attributes
    • textContent

      public abstract String textContent()
      Returns the text content of an element.
      Returns:
      the text content or an empty string if non exists
    • textContent

      public abstract SpinXmlElement textContent(String textContent)
      Sets the text content of an element.
      Parameters:
      textContent - the text content to set
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the textContent is null
    • childElement

      public abstract SpinXmlElement childElement(String elementName)
      Returns a single wrapped child element for the given name in the local namespace of this element.
      Parameters:
      elementName - the element name
      Returns:
      the wrapped child element
      Throws:
      IllegalArgumentException - if the elementName is null
      SpinXmlElementException - if none or more than one child element is found
    • childElement

      public abstract SpinXmlElement childElement(String namespace, String elementName)
      Returns a single wrapped child element for the given namespace and name.
      Parameters:
      namespace - the namespace of the element
      elementName - the element name
      Returns:
      the wrapped child element
      Throws:
      IllegalArgumentException - if the elementName is null
      SpinXmlElementException - if none or more than one child element is found
    • childElements

      public abstract SpinList<SpinXmlElement> childElements()
      Returns all child elements of this elements.
      Returns:
      list of wrapped child elements
    • childElements

      public abstract SpinList<SpinXmlElement> childElements(String elementName)
      Returns all child elements with a given name in the local namespace of this element.
      Parameters:
      elementName - the element name
      Returns:
      a collection of wrapped elements
      Throws:
      IllegalArgumentException - if the element name is null
      SpinXmlElementException - if no child element was found
    • childElements

      public abstract SpinList<SpinXmlElement> childElements(String namespace, String elementName)
      Returns all child elements with a given namespace and name.
      Parameters:
      namespace - the namespace of the element
      elementName - the element name
      Returns:
      a collection of wrapped elements
      Throws:
      IllegalArgumentException - if the element name is null
      SpinXmlElementException - if no child element was found
    • append

      public abstract SpinXmlElement append(SpinXmlElement... childElements)
      Appends child elements to this element.
      Parameters:
      childElements - the child elements to append
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the childElements is null or one of them
      SpinXmlElementImplementationException - if a child element cannot be appended in the underlying implementation
    • append

      public abstract SpinXmlElement append(Collection<SpinXmlElement> childElements)
      Appends child elements to this element.
      Parameters:
      childElements - the child elements to append
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the childElements is null or one of them
      SpinXmlElementImplementationException - if a child element cannot be appended in the underlying implementation
    • appendBefore

      public abstract SpinXmlElement appendBefore(SpinXmlElement childElement, SpinXmlElement existingChildElement)
      Appends a child element to this element before the existing child element.
      Parameters:
      childElement - the child element to append
      existingChildElement - the child element to append before
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the child element or existing child element is null
      SpinXmlElementException - if the existing child element is not a child of this element
      SpinXmlElementImplementationException - if the new child element cannot be inserted in the underlying implementation
    • appendAfter

      public abstract SpinXmlElement appendAfter(SpinXmlElement childElement, SpinXmlElement existingChildElement)
      Appends a child element to this element after the existing child element.
      Parameters:
      childElement - the child element to append
      existingChildElement - the child element to append after
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if the child element or existing child element is null
      SpinXmlElementException - if the existing child element is not a child of this element
      SpinXmlElementImplementationException - if the new child element cannot be inserted in the underlying implementation
    • remove

      public abstract SpinXmlElement remove(SpinXmlElement... childElements)
      Removes all child elements from this element.
      Parameters:
      childElements - the child elements to remove
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if child elements is null or any of them
      SpinXmlElementException - if one of the child elements does not exist
      SpinXmlElementImplementationException - if the child element cannot be removed in the underlying implementation
    • remove

      public abstract SpinXmlElement remove(Collection<SpinXmlElement> childElements)
      Removes all child elements from this element.
      Parameters:
      childElements - the child elements to remove
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if child elements is null or any of them
      SpinXmlElementException - if one of the child elements does not exist
      SpinXmlElementImplementationException - if the child element cannot be removed in the underlying implementation
    • replace

      public abstract SpinXmlElement replace(SpinXmlElement newChildElement)
      Replaces this element by an new one.
      Parameters:
      newChildElement - the new element
      Returns:
      the new wrapped element
      Throws:
      IllegalArgumentException - if the new element is null or has the wrong type
      SpinXmlElementException - if this element has no parent element
      SpinXmlElementImplementationException - if the element cannot be replaced in the underlying implementation
    • replaceChild

      public abstract SpinXmlElement replaceChild(SpinXmlElement existingChildElement, SpinXmlElement newChildElement)
      Replaces an existing child element with a new one.
      Parameters:
      existingChildElement - the existing child element to replace
      newChildElement - the new child element
      Returns:
      the wrapped element
      Throws:
      IllegalArgumentException - if any of the child elements is null
      SpinXmlElementException - if the existing element is not a child element of this
      SpinXmlElementImplementationException - if the child cannot be replaced in the underlying implementation
    • xPath

      public abstract SpinXPathQuery xPath(String expression)
      Creates a XPath query on this element.
      Parameters:
      expression - the XPath expression
      Returns:
      the XPath query
    • toString

      public abstract String toString()
      Returns the wrapped XML element as string representation.
      Specified by:
      toString in class Spin<SpinXmlElement>
      Returns:
      the string representation
      Throws:
      SpinXmlElementException - if the element cannot be transformed or no new transformer can be created
    • writeToWriter

      public abstract void writeToWriter(Writer writer)
      Writes the wrapped XML element to a existing writer.
      Specified by:
      writeToWriter in class Spin<SpinXmlElement>
      Parameters:
      writer - the writer to write to
      Throws:
      SpinXmlElementException - if the element cannot be transformed or no new transformer can be created