Library: FastInfoset
Package: Writer
Header: Poco/FastInfoset/FastInfosetWriter.h
This class serializes SAX2 ContentHandler, LexicalHandler and DTDHandler events into a Fast Infoset stream.
Various consistency checks are performed on the written data (i.e. there must be exactly one root element and every startElement() must have a matching endElement()).
The writer contains extensive support for XML Namespaces, so that a client application does not have to keep track of prefixes and supply xmlns attributes.
If the client does not provide namespace prefixes (either by specifying them as part of the qualified name given to startElement(), or by calling startPrefixMapping()), the XMLWriter automatically generates namespace prefixes in the form ns1, ns2, etc.
The writer supports automatic indexing of character data element content. Only character data with a given maximum length (default is 7) will be indexed. The length can be set with setMaxIndexedStringLength().
Direct Base Classes: FISContentHandler, Poco::XML::LexicalHandler, Poco::XML::DTDHandler, FISDocumentHandler
All Base Classes: FISContentHandler, FISDocumentHandler, Poco::XML::ContentHandler, Poco::XML::DTDHandler, Poco::XML::LexicalHandler
Member Functions: addAttributes, addNamespaceAttributes, binaryData, characters, comment, dataElement, declareAttributeNamespaces, emptyElement, encodedData, endCDATA, endDTD, endDocument, endElement, endEntity, endFragment, endPrefixMapping, getDocumentVocabulary, getMaxIndexedStringLength, handleEncodedData, handleNamespaces, ignorableWhitespace, nameToString, newPrefix, notationDecl, processingInstruction, setDocumentLocator, setDocumentVocabulary, setExternalVocabulary, setMaxIndexedStringLength, setWriteXMLDeclaration, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startFragment, startPrefixMapping, unparsedEntityDecl
Inherited Functions: binaryData, characters, comment, encodedData, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, getDocumentVocabulary, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, setDocumentVocabulary, setExternalVocabulary, setWriteXMLDeclaration, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startPrefixMapping, unparsedEntityDecl
typedef std::map < std::string, std::string > AttributeMap;
Maps an attribute namespace prefix to a URI.
typedef std::vector < AttributeValue > AttributeValues;
typedef std::vector < State > States;
FastInfosetWriter(
std::ostream & str
);
Creates the FastInfosetWriter.
No XML declaration is included in the generated Fast Infoset document.
FastInfosetWriter(
std::ostream & str,
bool writeXMLDeclaration,
const DocumentVocabulary & initialVocabulary
);
Creates the FastInfosetWriter using the given initial document vocabulary. Passing an initial, populated document vocabulary can speed up the generation of the Fast Infoset stream.
If writeXMLDeclaration is true, an XML declaration is included in the resulting Fast Infoset document.
FastInfosetWriter(
std::ostream & str,
bool writeXMLDeclaration,
DocumentVocabulary::VocabularyImpl vocImpl = DocumentVocabulary::VOC_HASH
);
Creates the FastInfosetWriter.
If writeXMLDeclaration is true, an XML declaration is included in the resulting Fast Infoset document.
Specify DocumentVocabulary::VOC_HASH or DocumentVocabulary::VOC_MAP for vocImpl (DocumentVocabulary::VOC_VECTOR cannot be used with the writer). VOC_MAP has the advantage that it does not impose any restrictions to the size of a vocabulary (except for available physical memory). For very large documents, the hash tables of a hash vocabulary may overflow. In contrast, the size of a map vocabulary is only restricted by available memory. Parsing performance may be slightly better with a hash vocabulary, though.
Destroys the FastInfosetWriter.
void binaryData(
const char * buffer,
std::size_t size
);
void characters(
const char ch[],
int start,
int length
);
Writes XML character data.
The characters must be encoded in UTF-8.
void characters(
const std::string & str
);
Writes XML character data.
The characters must be encoded in UTF-8.
void comment(
const char ch[],
int start,
int length
);
Writes a comment.
void dataElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname,
const std::string & data,
const std::string & attr1 = std::string (),
const std::string & value1 = std::string (),
const std::string & attr2 = std::string (),
const std::string & value2 = std::string (),
const std::string & attr3 = std::string (),
const std::string & value3 = std::string ()
);
Writes a data element in the form <name attr1="value1"...>data</name>.
void emptyElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname
);
Writes an empty XML element tag (<elem/>).
void emptyElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname,
const Poco::XML::Attributes & attributes
);
Writes an empty XML element tag with the given attributes (<elem attr1="value1"... />).
void encodedData(
Poco::Int16 value
);
void encodedData(
Poco::Int32 value
);
void encodedData(
Poco::Int64 value
);
void encodedData(
bool value
);
void encodedData(
float value
);
void encodedData(
double value
);
void encodedData(
const Poco::UUID & uuid
);
template < typename T > void encodedData(
const std::vector < T > & vec
);
template < typename T > void encodedData(
const std::set < T > & val
);
void endCDATA();
Writes the ] string that ends a CDATA section.
See also: Poco::XML::LexicalHandler::endCDATA()
void endDTD();
Writes the closing characters of a DTD declaration.
See also: Poco::XML::LexicalHandler::endDTD()
void endDocument();
Checks that all elements are closed and prints a final newline.
See also: Poco::XML::ContentHandler::endDocument()
void endElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname
);
Writes an XML end element tag.
Throws an exception if the name of doesn't match the one of the most recent startElement().
void endEntity(
const std::string & name
);
Does nothing.
void endFragment();
Document fragments are not supported by FIS. Will throw an exception.
void endPrefixMapping(
const std::string & prefix
);
End the scope of a prefix-URI mapping.
DocumentVocabulary & getDocumentVocabulary();
Returns the documentVocabulary
const DocumentVocabulary & getDocumentVocabulary() const;
Returns the documentVocabulary as a const object
int getMaxIndexedStringLength() const;
Returns the maximum length for indexed character data.
Character data element content which is shorter than the given length will be indexed in the resulting Fast Infoset document.
void ignorableWhitespace(
const char ch[],
int start,
int length
);
Writes whitespace characters by simply passing them to characters().
void notationDecl(
const std::string & name,
const std::string * publicId,
const std::string * systemId
);
Writes a notation to the header. startDocument must not have been called yet!
void processingInstruction(
const std::string & target,
const std::string & data
);
Writes a processing instruction.
void setDocumentLocator(
const Poco::XML::Locator * loc
);
Unused for Fast Infoset documents.
void setDocumentVocabulary(
const DocumentVocabulary & voc
);
Sets the documentVocabulary. Only accepts default vocabularies.
void setExternalVocabulary(
const std::string & uri,
const DocumentVocabulary & voc
);
Sets the location of the external dictionary and its content. The content is required so we can create a diff to the finally set initial vocabulary and encode only the difference!
void setMaxIndexedStringLength(
int length
);
Sets the maximum length for indexed character data.
Character data element content which is shorter than the given length will be indexed in the resulting Fast Infoset document.
void setWriteXMLDeclaration(
bool val
);
Set to true if an XML declaration should be written.
void skippedEntity(
const std::string & name
);
Does nothing.
void startCDATA();
Writes the [CDATA[ string that begins a CDATA section. Use characters() to write the actual character data.
See also: Poco::XML::LexicalHandler::startCDATA()
void startDTD(
const std::string & name,
const std::string & publicId,
const std::string & systemId
);
Writes a DTD declaration.
void startDocument();
Writes a generic XML declaration to the stream. If a document type has been set (see SetDocumentType), a DOCTYPE declaration is also written.
void startElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname,
const Poco::XML::Attributes & attributes
);
Writes an XML start element tag.
Namespaces are handled as follows.
void startElement(
const std::string & namespaceURI,
const std::string & localName,
const std::string & qname
);
Writes an XML start element tag with no attributes. See the other startElement() method for more information.
void startEntity(
const std::string & name
);
Does nothing.
void startFragment();
Document fragments are not supported by Fast Infoset. Will throw an exception.
void startPrefixMapping(
const std::string & prefix,
const std::string & namespaceURI
);
Begin the scope of a prefix-URI Namespace mapping. A namespace declaration is written with the next element.
void unparsedEntityDecl(
const std::string & name,
const std::string * publicId,
const std::string & systemId,
const std::string & notationName
);
Writes a unparsed entity to the header. startDocument must not have been called yet!
void addAttributes(
AttributeValues & attributeVals,
const Poco::XML::Attributes & attributes,
const std::string & elementNamespaceURI
);
Extracts all non-namespace attributes from parameter attributes and adds them to attributeVals,
void addNamespaceAttributes(
AttributeMap & attributeMap
);
Checks which namespaces are new in the current state and returns them in the AttributeMap.
void declareAttributeNamespaces(
const Poco::XML::Attributes & attributes
);
Declares the namespaces.
void handleEncodedData();
Serializes any encoded character data, if present.
void handleNamespaces(
const Poco::XML::Attributes & attributes,
const std::string & elementNamespaceURI,
AttributeMap & nsAttributeMap,
AttributeValues & attributeVal
);
Handles namespaces.
const std::string & nameToString(
const std::string & localName,
const std::string & qname
) const;
Returns either the localname of the qname.
std::string newPrefix();
Creates a new prefix.