Package net.sf.saxon.s9api.push
Interface Push
-
- All Known Implementing Classes:
PushToReceiver
public interface Push
An interface designed for applications to generate XML documents by issuing events. Functionally similar to the SAXContentHandler
or the StaxXMLStreamWriter
, it is designed eliminate the usability problems and ambiguities in those specifications.The
Push
interface can be used to create a single tree rooted at a document node. It is possible to constrain the document node to be well-formed (in which case it must have a single element node child, plus optionally comment and processing instruction children). Some implementations may only accept well-formed documents.The document created using the
Push
interface is set to theDestination
defined whenPush
is created using the factory methodProcessor.newPush(Destination)
. TheDestination
will commonly be anXdmDestination
or aSerializer
, but it could also be, for example, anXsltTransformer
or anSchemaValidator
.Here is an example of application code written to construct a simple XML document:
Document doc = processor.newPush(destination).document(true); doc.setDefaultNamespace("http://www.example.org/ns"); Element top = doc.element("root") .attribute("version", "1.5"); for (Employee emp : employees) { top.element("emp") .attribute("ssn", emp.getSSN()) .text(emp.getName()); } doc.close();
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Document
document(boolean wellFormed)
Start an XML document.
-
-
-
Method Detail
-
document
Document document(boolean wellFormed) throws SaxonApiException
Start an XML document.- Parameters:
wellFormed
- Set to true if the document is required to be well-formed; set to false if there is no such requirement. A well-formed document must have as its children exactly one element node plus optionally, any number of comment and processing instruction nodes (no text nodes are allowed); any attempt to construct a node sequence that does not follow these rules will result in an exception. If the document is not required to be well-formed, the children of the document node may comprise any sequence of element, text, comment, and processing instruction nodes.- Returns:
- a Document object which may be used to add content to the document, or to close the document when it has been fully written.
- Throws:
SaxonApiException
- if the specified constraints are violated, or if the implementation detects any problems
-
-