public class XMLBuilder extends BasicBuilder
uk.ac.sheffield.jast.xml
.
All the XML model content and metadata are stored as part of the model, which by default is compact (discarding formatting whitespace surrounding XML elements). XMLBuilder may be requested to preserve full native format (keeping all original layout text as extra Text nodes). The model is accessed as an instance of Document.
By default, XMLBuilder will return a well-formed XML Document, or report that the XML syntax was faulty. XMLBuilder may be requested to validate the Document, to ensure that it conforms to some grammar defined by a Doctype, or an XML schema, so long as the Document refers to these. It may also be instructed to expand new entity references as part of a Doctype.
Modifier and Type | Field and Description |
---|---|
private Content |
current
The current Content being constructed by this builder.
|
private Doctype |
doctype
The Doctype declaration for the Document, if it exists.
|
private Document |
document
The top-level Document constructed by this builder.
|
private boolean |
rawLayout
A flag describing whether to preserve the native format of the XML.
|
private Element |
rootElement
The root Element for the Document.
|
lexicon, parser, validation
Constructor and Description |
---|
XMLBuilder()
Constructs an XMLBuilder.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String identifier,
java.lang.String value)
Adds an attribute with the given name and value to the current node.
|
void |
addComment(java.lang.String text)
Adds an XML comment to the current node.
|
void |
addEscapedData(java.lang.String data)
Adds escaped data to the current node.
|
void |
addLayoutText(java.lang.String text)
Adds layout text to the current node.
|
void |
addPrintingText(java.lang.String text)
Adds printing text to the current node.
|
void |
endDeclaration()
Finishes processing the XML declaration.
|
void |
endDoctype()
Finishes processing an XML doctype declaration.
|
void |
endDocument()
Finishes processing the XML document.
|
void |
endElement()
Finishes processing an XML element.
|
void |
endInstruction()
Finishes processing an XML processing instruction.
|
Document |
getDocument()
Returns the document that was built by this XMLBuilder.
|
void |
preserveLayout(boolean value)
Instructs this XMLBuilder whether to preserve, or ignore layout text.
|
void |
startDeclaration(java.lang.String target)
Starts to process the XML declaration.
|
void |
startDoctype(java.lang.String root)
Starts to process an XML doctype declaration.
|
void |
startDocument()
Starts to construct a Document.
|
void |
startElement(java.lang.String identifier)
Starts to process an XML element.
|
void |
startInstruction(java.lang.String target)
Starts to process an XML processing instruction.
|
protected void |
validate(Document document)
Validates the Document using its own XMLSchema.
|
checkEncoding, endOfStream, getContext, getLexicon, getLineNumber, getParser, setLexicon, setParser, setValidation
encodingError, semanticError, syntaxError
private Content current
private Document document
private Doctype doctype
private Element rootElement
private boolean rawLayout
public void preserveLayout(boolean value)
value
- true, to retain a Document with all original layout text.public Document getDocument()
getDocument
in interface Builder
getDocument
in class BasicBuilder
public void startDocument()
startDocument
in interface Builder
startDocument
in class BasicBuilder
public void endDocument() throws java.io.IOException, SyntaxError, SemanticError
endDocument
in interface Builder
endDocument
in class BasicBuilder
java.io.IOException
- when validating, if an XMLSchema could not be read.SyntaxError
- when validating, if a faulty XMLSchema is read.SemanticError
- if the XML document is found to be invalid.public void startDeclaration(java.lang.String target)
startDeclaration
in interface Builder
startDeclaration
in class BasicBuilder
target
- the symbol "xml" or "XML".public void endDeclaration() throws java.io.UnsupportedEncodingException
endDeclaration
in interface Builder
endDeclaration
in class BasicBuilder
java.io.UnsupportedEncodingException
- if the declared encoding does
not match the actual encoding.public void startInstruction(java.lang.String target)
startInstruction
in interface Builder
startInstruction
in class BasicBuilder
target
- the name of the processing instruction.public void endInstruction()
endInstruction
in interface Builder
endInstruction
in class BasicBuilder
public void startDoctype(java.lang.String root)
startDoctype
in interface Builder
startDoctype
in class BasicBuilder
root
- the name of the root element.public void endDoctype() throws java.io.IOException, SyntaxError
endDoctype
in interface Builder
endDoctype
in class BasicBuilder
java.io.IOException
- if reading an external DTD file fails.SyntaxError
- if the DTD syntax is faulty.public void startElement(java.lang.String identifier)
startElement
in interface Builder
startElement
in class BasicBuilder
identifier
- the name of the element.public void endElement()
endElement
in interface Builder
endElement
in class BasicBuilder
public void addAttribute(java.lang.String identifier, java.lang.String value)
addAttribute
in interface Builder
addAttribute
in class BasicBuilder
identifier
- the name of the attribute.value
- the value of the attribute.public void addComment(java.lang.String text)
addComment
in interface Builder
addComment
in class BasicBuilder
text
- the comment text.public void addPrintingText(java.lang.String text)
addPrintingText
in interface Builder
addPrintingText
in class BasicBuilder
text
- the printing character text.public void addLayoutText(java.lang.String text)
addLayoutText
in interface Builder
addLayoutText
in class BasicBuilder
text
- the formatting whitespace.public void addEscapedData(java.lang.String data)
addEscapedData
in interface Builder
addEscapedData
in class BasicBuilder
data
- the escaped character data.protected void validate(Document document) throws java.io.UnsupportedEncodingException, java.io.IOException, SyntaxError, SemanticError
document
- the Document.java.io.UnsupportedEncodingException
- if an encoding fault occurs.java.io.IOException
- if any other I/O error occurs.SyntaxError
- if the XML syntax is faulty.SemanticError
- if schema constraints are broken.