Package org.arakhne.afc.inputoutput.xml
Interface XMLBuilder
-
public interface XMLBuilder
This interface permits to create several XML elements.- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:40
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- inputoutput
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Attr
createAttribute(String name)
Creates anAttr
of the given name.default Attr
createAttributeNS(String namespaceURI, String qualifiedName)
Creates an attribute of the given qualified name and namespace URI.default CDATASection
createCDATASection(String data)
Creates aCDATASection
node whose value is the specified string.default Comment
createComment(String data)
Creates aComment
node given the specified string.default DocumentFragment
createDocumentFragment()
Creates an emptyDocumentFragment
object.default Element
createElement(String tagName)
Creates an element of the type specified.default Element
createElementNS(String namespaceURI, String qualifiedName)
Creates an element of the given qualified name and namespace URI.default EntityReference
createEntityReference(String name)
Creates anEntityReference
object.default ProcessingInstruction
createProcessingInstruction(String target, String data)
Creates aProcessingInstruction
node given the specified name and data strings.default Element
createTextElement(String tagName, String data)
Creates an element that contains the given text.default Text
createTextNode(String data)
Creates aText
node given the specified string.Document
getDocument()
Replies the document associated to this builder.
-
-
-
Method Detail
-
getDocument
Document getDocument() throws DOMException
Replies the document associated to this builder.- Returns:
- the document associated to this builder.
- Throws:
DOMException
- if it is impossible to get the document.
-
createElement
default Element createElement(String tagName) throws DOMException
Creates an element of the type specified. Note that the instance returned implements theElement
interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values,Attr
nodes representing them are automatically created and attached to the element.
To create an element with a qualified name and namespace URI, use thecreateElementNS
method.- Parameters:
tagName
- The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation.- Returns:
- A new
Element
object with thenodeName
attribute set totagName
, andlocalName
,prefix
, andnamespaceURI
set tonull
. - Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
-
createDocumentFragment
default DocumentFragment createDocumentFragment()
Creates an emptyDocumentFragment
object.- Returns:
- A new
DocumentFragment
.
-
createTextNode
default Text createTextNode(String data)
Creates aText
node given the specified string.- Parameters:
data
- The data for the node.- Returns:
- The new
Text
object. - See Also:
createTextElement(String, String)
-
createTextElement
default Element createTextElement(String tagName, String data)
Creates an element that contains the given text.Note that the instance returned implements the
Element
interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values,Attr
nodes representing them are automatically created and attached to the element.This function is equivalent to:
Element e = createElement(tagName); Text t = createText(data); e.appendChild(t); return e;
- Parameters:
tagName
- The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation.data
- The data for the node.- Returns:
- the Element with the Text inside.
- See Also:
createTextNode(String)
,createElement(String)
-
createComment
default Comment createComment(String data)
Creates aComment
node given the specified string.- Parameters:
data
- The data for the node.- Returns:
- The new
Comment
object.
-
createCDATASection
default CDATASection createCDATASection(String data) throws DOMException
Creates aCDATASection
node whose value is the specified string.- Parameters:
data
- The data for theCDATASection
contents.- Returns:
- The new
CDATASection
object. - Throws:
DOMException
- NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
-
createProcessingInstruction
default ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException
Creates aProcessingInstruction
node given the specified name and data strings.- Parameters:
target
- The target part of the processing instruction.UnlikeDocument.createElementNS
orDocument.createAttributeNS
, no namespace well-formed checking is done on the target name. Applications should invokeDocument.normalizeDocument()
with the parameter " namespaces" set totrue
in order to ensure that the target name is namespace well-formed.data
- The data for the node.- Returns:
- The new
ProcessingInstruction
object. - Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified target is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
-
createAttribute
default Attr createAttribute(String name) throws DOMException
Creates anAttr
of the given name. Note that theAttr
instance can then be set on anElement
using thesetAttributeNode
method.
To create an attribute with a qualified name and namespace URI, use thecreateAttributeNS
method.- Parameters:
name
- The name of the attribute.- Returns:
- A new
Attr
object with thenodeName
attribute set toname
, andlocalName
,prefix
, andnamespaceURI
set tonull
. The value of the attribute is the empty string. - Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
-
createEntityReference
default EntityReference createEntityReference(String name) throws DOMException
Creates anEntityReference
object. In addition, if the referenced entity is known, the child list of theEntityReference
node is made the same as that of the correspondingEntity
node.Note: If any descendant of the
Entity
node has an unbound namespace prefix, the corresponding descendant of the createdEntityReference
node is also unbound; (itsnamespaceURI
isnull
). The DOM Level 2 and 3 do not support any mechanism to resolve namespace prefixes in this case.- Parameters:
name
- The name of the entity to reference.UnlikeDocument.createElementNS
orDocument.createAttributeNS
, no namespace well-formed checking is done on the entity name. Applications should invokeDocument.normalizeDocument()
with the parameter " namespaces" set totrue
in order to ensure that the entity name is namespace well-formed.- Returns:
- The new
EntityReference
object. - Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
-
createElementNS
default Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException
Creates an element of the given qualified name and namespace URI.
Per [XML Namespaces] , applications must use the valuenull
as the namespaceURI parameter for methods if they wish to have no namespace.- Parameters:
namespaceURI
- The namespace URI of the element to create.qualifiedName
- The qualified name of the element type to instantiate.- Returns:
- A new
Element
object with the following attributes:Attribute Value Node.nodeName
qualifiedName
Node.namespaceURI
namespaceURI
Node.prefix
prefix, extracted from qualifiedName
, ornull
if there is no prefixNode.localName
local name, extracted from qualifiedName
Element.tagName
qualifiedName
- Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specifiedqualifiedName
is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
NAMESPACE_ERR: Raised if thequalifiedName
is a malformed qualified name, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, or if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from " http://www.w3.org/XML/1998/namespace" [XML Namespaces], or if thequalifiedName
or its prefix is "xmlns" and thenamespaceURI
is different from "http://www.w3.org/2000/xmlns/", or if thenamespaceURI
is "http://www.w3.org/2000/xmlns/" and neither thequalifiedName
nor its prefix is "xmlns".
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the"XML"
feature, since namespaces were defined by XML.- Since:
- DOM Level 2
-
createAttributeNS
default Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException
Creates an attribute of the given qualified name and namespace URI.
Per [XML Namespaces] , applications must use the valuenull
as thenamespaceURI
parameter for methods if they wish to have no namespace.- Parameters:
namespaceURI
- The namespace URI of the attribute to create.qualifiedName
- The qualified name of the attribute to instantiate.- Returns:
- A new
Attr
object with the following attributes:Attribute Value Node.nodeName
qualifiedName Node.namespaceURI
namespaceURI
Node.prefix
prefix, extracted from qualifiedName
, ornull
if there is no prefixNode.localName
local name, extracted from qualifiedName
Attr.name
qualifiedName
Node.nodeValue
the empty string - Throws:
DOMException
- INVALID_CHARACTER_ERR: Raised if the specifiedqualifiedName
is not an XML name according to the XML version in use specified in theDocument.xmlVersion
attribute.
NAMESPACE_ERR: Raised if thequalifiedName
is a malformed qualified name, if thequalifiedName
has a prefix and thenamespaceURI
isnull
, if thequalifiedName
has a prefix that is "xml" and thenamespaceURI
is different from " http://www.w3.org/XML/1998/namespace", if thequalifiedName
or its prefix is "xmlns" and thenamespaceURI
is different from "http://www.w3.org/2000/xmlns/", or if thenamespaceURI
is "http://www.w3.org/2000/xmlns/" and neither thequalifiedName
nor its prefix is "xmlns".
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the"XML"
feature, since namespaces were defined by XML.- Since:
- DOM Level 2
-
-