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, setValidationencodingError, semanticError, syntaxErrorprivate 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 BuildergetDocument in class BasicBuilderpublic void startDocument()
startDocument in interface BuilderstartDocument in class BasicBuilderpublic void endDocument()
throws java.io.IOException,
SyntaxError,
SemanticError
endDocument in interface BuilderendDocument in class BasicBuilderjava.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 BuilderstartDeclaration in class BasicBuildertarget - the symbol "xml" or "XML".public void endDeclaration()
throws java.io.UnsupportedEncodingException
endDeclaration in interface BuilderendDeclaration in class BasicBuilderjava.io.UnsupportedEncodingException - if the declared encoding does
not match the actual encoding.public void startInstruction(java.lang.String target)
startInstruction in interface BuilderstartInstruction in class BasicBuildertarget - the name of the processing instruction.public void endInstruction()
endInstruction in interface BuilderendInstruction in class BasicBuilderpublic void startDoctype(java.lang.String root)
startDoctype in interface BuilderstartDoctype in class BasicBuilderroot - the name of the root element.public void endDoctype()
throws java.io.IOException,
SyntaxError
endDoctype in interface BuilderendDoctype in class BasicBuilderjava.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 BuilderstartElement in class BasicBuilderidentifier - the name of the element.public void endElement()
endElement in interface BuilderendElement in class BasicBuilderpublic void addAttribute(java.lang.String identifier,
java.lang.String value)
addAttribute in interface BuilderaddAttribute in class BasicBuilderidentifier - the name of the attribute.value - the value of the attribute.public void addComment(java.lang.String text)
addComment in interface BuilderaddComment in class BasicBuildertext - the comment text.public void addPrintingText(java.lang.String text)
addPrintingText in interface BuilderaddPrintingText in class BasicBuildertext - the printing character text.public void addLayoutText(java.lang.String text)
addLayoutText in interface BuilderaddLayoutText in class BasicBuildertext - the formatting whitespace.public void addEscapedData(java.lang.String data)
addEscapedData in interface BuilderaddEscapedData in class BasicBuilderdata - 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.