Module org.tquadrat.foundation.xml
Interface XMLDocument
- All Superinterfaces:
Document<XMLElement>
- All Known Implementing Classes:
XMLDocumentImpl
@ClassVersion(sourceVersion="$Id: XMLDocument.java 1071 2023-09-30 01:49:32Z tquadrat $")
@API(status=STABLE,
since="0.0.5")
public sealed interface XMLDocument
extends Document<XMLElement>
permits XMLDocumentImpl
The definition for an XML document.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: XMLDocument.java 1071 2023-09-30 01:49:32Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.xml.builder.XMLDocument"
-
Method Summary
Modifier and TypeMethodDescriptiondefault XMLDocumentaddChild(XMLElement child) Adds a child to the root element of this document.default XMLDocumentaddComment(CharSequence comment) Adds a comment to the root element of this document.default XMLDocumentaddDocumentComment(CharSequence comment) Adds a comment to the document itself.default XMLDocumentaddPredefinedMarkup(CharSequence markup) Adds predefined XML markup to the root element of this document.default XMLDocumentaddProcessingInstruction(ProcessingInstruction processingInstruction) Adds a processing instruction to this document.default XMLDocumentsetAttribute(String name, boolean flag) Sets the attribute with the given name to the root element of this document.
The method usesBoolean.toString(boolean)to convert the provided flag to aString.default XMLDocumentsetAttribute(String name, double number) Sets the attribute with the given name to the root element of this document.
The method usesDouble.toString(double)to convert the provided number to aString.default XMLDocumentsetAttribute(String name, int number) Sets the attribute with the given name to the root element of this document.
The method usesInteger.toString(int)to convert the provided number to aString.default XMLDocumentsetAttribute(String name, long number) Sets the attribute with the given name to the root element of this document.
The method usesLong.toString(long)to convert the provided number to aString.default <E extends Enum<E>>
XMLDocumentsetAttribute(String name, E enumValue) Sets the attribute with the given name to the root element of this document.
The method usesEnum.name()to convert the provided value to aString.default XMLDocumentsetAttribute(String name, Boolean flag) Sets the attribute with the given name to the root element of this document.
The method usesBoolean.toString()to convert the provided flag to aString.default XMLDocumentsetAttribute(String name, CharSequence value) Sets the attribute with the given name to the root element of this document.default XMLDocumentsetAttribute(String name, CharSequence value, Optional<? extends CharSequence> append) Sets the attribute with the given name to the root element of this document.default XMLDocumentsetAttribute(String name, Number number) Sets the attribute with the given name to the root element of this document.
The method usesObject.toString()to convert the provided number to aString.default XMLDocumentsetAttribute(String name, Instant date) Sets the attribute with the given name to the root element of this document.
The method usesInstant.toString()to convert the provided number to aString.default XMLDocumentsetAttribute(String name, LocalDate date) Sets the attribute with the given name to the root element of this document.
The method usesLocalDate.toString()to convert the provided number to aString.default XMLDocumentsetAttribute(String name, LocalDateTime date) Sets the attribute with the given name to the root element of this document.
The method usesLocalDateTime.toString()to convert the provided number to aString.default XMLDocumentsetAttribute(String name, ZonedDateTime date) Sets the attribute with the given name to the root element of this document.
The method usesZonedDateTime.toString()to convert the provided number to aString.default XMLDocumentsetAttributeIfNotEmpty(String name, CharSequence value) Sets the attribute with the given name to the root element of this document if the provided value is not empty.
The method usesStringUtils.isNotEmpty(CharSequence)to test if the given value is empty.default XMLDocumentsetAttributeIfNotEmpty(String name, Optional<? extends CharSequence> optional) Sets the attribute with the given name to the root element of this document if the provided value is not empty.default XMLDocumentSets the id for the root element of this document.
The value will be validated using the method that is provided by a call toXMLBuilderUtils.getNMTokenValidator().default XMLDocumentsetNamespace(String identifier) Sets the given namespace to the root element of this document.default XMLDocumentsetNamespace(String prefix, String identifier) Sets the given namespace to the root element of this document.
The given prefix is validated using the method that is provided byXMLBuilderUtils.getPrefixValidator().default XMLDocumentsetNamespace(String prefix, URI identifier) Sets the given namespace to the root element of this document.
The given prefix is validated using the method that is provided byXMLBuilderUtils.getPrefixValidator().default XMLDocumentsetNamespace(URI identifier) Sets the given namespace to the root element of this document.default XMLDocumentsetNamespace(Namespace namespace) Sets the given namespace to the root element of this document.Methods inherited from interface org.tquadrat.foundation.xml.builder.spi.Document
getAttribute, getAttributes, getChildren, getElementName, getNamespaces, getRootElement, toString
-
Method Details
-
addChild
default XMLDocument addChild(XMLElement child) throws IllegalArgumentException, IllegalStateException Adds a child to the root element of this document.- Parameters:
child- The child to add.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The child is not allowed for the root element of this document, or the root element does not allow adding children at all.IllegalStateException- The child has already a parent that is not the root XML element.
-
addComment
Adds a comment to the root element of this document.- Parameters:
comment- The comment to add.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The root element does not allow adding comments.
-
addDocumentComment
Adds a comment to the document itself.- Parameters:
comment- The comment to add.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The document does not allow adding comments.
-
addPredefinedMarkup
Adds predefined XML markup to the root element of this document. The given markup will not be validated, it just may not benull. So the caller is responsible that it will be proper XML.
As the markup may be formatted differently (or not formatted at all), the pretty printed output may be distorted when this is used.- Parameters:
markup- The XML markup.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The root element does not allow adding children at all.
-
addProcessingInstruction
default XMLDocument addProcessingInstruction(ProcessingInstruction processingInstruction) throws IllegalArgumentException, IllegalStateException Adds a processing instruction to this document.- Parameters:
processingInstruction- The procession instruction to add.- Returns:
- This instance.
- Throws:
IllegalArgumentException- This document does not allow adding processing instructions.IllegalStateException- The processing instruction has already a parent.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesBoolean.toString(boolean)to convert the provided flag to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.flag- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesBoolean.toString()to convert the provided flag to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.flag- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.- Parameters:
name- The name of the attribute; the name is case-sensitive.value- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
default XMLDocument setAttribute(String name, CharSequence value, Optional<? extends CharSequence> append) throws IllegalArgumentException Sets the attribute with the given name to the root element of this document.- Parameters:
name- The name of the attribute; the name is case-sensitive.value- The attribute's value; ifnullthe attribute will be removed.append- If not empty, the new value will be appended on an already existing one, and this sequence is used as the separator.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesDouble.toString(double)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
default <E extends Enum<E>> XMLDocument setAttribute(String name, E enumValue) throws IllegalArgumentException Sets the attribute with the given name to the root element of this document.
The method usesEnum.name()to convert the provided value to aString.- Type Parameters:
E- The concrete enum type ofvalue.- Parameters:
name- The name of the attribute; the name is case-sensitive.enumValue- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesInstant.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesInteger.toString(int)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesLocalDate.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesLocalDateTime.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesLong.toString(long)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesObject.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttribute
Sets the attribute with the given name to the root element of this document.
The method usesZonedDateTime.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttributeIfNotEmpty
default XMLDocument setAttributeIfNotEmpty(String name, CharSequence value) throws IllegalArgumentException Sets the attribute with the given name to the root element of this document if the provided value is not empty.
The method usesStringUtils.isNotEmpty(CharSequence)to test if the given value is empty.- Parameters:
name- The name of the attribute.value- The value for the attribute; can benull.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setAttributeIfNotEmpty
default XMLDocument setAttributeIfNotEmpty(String name, Optional<? extends CharSequence> optional) throws IllegalArgumentException Sets the attribute with the given name to the root element of this document if the provided value is not empty.- Parameters:
name- The name of the attribute.optional- The value for the attribute.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.
-
setId
Sets the id for the root element of this document.
The value will be validated using the method that is provided by a call toXMLBuilderUtils.getNMTokenValidator().- Parameters:
id- The id.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The attribute is not allowed for the root element, or the root element does not allow attributes at all.- See Also:
-
setNamespace
default XMLDocument setNamespace(String identifier) throws IllegalArgumentException, URISyntaxException Sets the given namespace to the root element of this document.- Parameters:
identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalArgumentException- Namespaces are not allowed for this element.URISyntaxException- The provided URI String is invalid.
-
setNamespace
Sets the given namespace to the root element of this document.- Parameters:
identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalArgumentException- Namespaces are not allowed for this element.
-
setNamespace
default XMLDocument setNamespace(String prefix, String identifier) throws IllegalArgumentException, URISyntaxException Sets the given namespace to the root element of this document.
The given prefix is validated using the method that is provided byXMLBuilderUtils.getPrefixValidator().- Parameters:
prefix- The namespace prefix.identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalArgumentException- Namespaces are not allowed for this element.URISyntaxException- The provided URI String is invalid.
-
setNamespace
Sets the given namespace to the root element of this document.
The given prefix is validated using the method that is provided byXMLBuilderUtils.getPrefixValidator().- Parameters:
prefix- The namespace prefix.identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalArgumentException- Namespaces are not allowed for this element.
-
setNamespace
Sets the given namespace to the root element of this document.- Parameters:
namespace- The namespace.- Returns:
- This instance.
- Throws:
IllegalArgumentException- Namespaces are not allowed for this element.
-
