Poco::FastInfoset

class FastInfosetWriter

File Information

Library: FastInfoset
Package: Writer
Header: Poco/FastInfoset/FastInfosetWriter.h

Description

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().

Inheritance

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 Summary

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

Nested Classes

struct AttributeValue protected

 

Types

AttributeMap protected

typedef std::map < std::string, std::string > AttributeMap;

Maps an attribute namespace prefix to a URI.

AttributeValues protected

typedef std::vector < AttributeValue > AttributeValues;

States protected

typedef std::vector < State > States;

Enumerations

State protected

UNINITIALIZED

INDOCUMENT

INELEMENT

INCDATA

INDTD

Constructors

FastInfosetWriter

FastInfosetWriter(
    std::ostream & str
);

Creates the FastInfosetWriter.

No XML declaration is included in the generated Fast Infoset document.

FastInfosetWriter

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

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.

Destructor

~FastInfosetWriter virtual

~FastInfosetWriter();

Destroys the FastInfosetWriter.

Member Functions

binaryData virtual

void binaryData(
    const char * buffer,
    std::size_t size
);

characters

void characters(
    const char ch[],
    int start,
    int length
);

Writes XML character data.

The characters must be encoded in UTF-8.

characters

void characters(
    const std::string & str
);

Writes XML character data.

The characters must be encoded in UTF-8.

comment

void comment(
    const char ch[],
    int start,
    int length
);

Writes a comment.

dataElement

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>.

emptyElement

void emptyElement(
    const std::string & namespaceURI,
    const std::string & localName,
    const std::string & qname
);

Writes an empty XML element tag (<elem/>).

emptyElement

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"... />).

encodedData virtual

void encodedData(
    Poco::Int16 value
);

encodedData virtual

void encodedData(
    Poco::Int32 value
);

encodedData virtual

void encodedData(
    Poco::Int64 value
);

encodedData virtual

void encodedData(
    bool value
);

encodedData virtual

void encodedData(
    float value
);

encodedData virtual

void encodedData(
    double value
);

encodedData virtual

void encodedData(
    const Poco::UUID & uuid
);

encodedData inline

template < typename T > void encodedData(
    const std::vector < T > & vec
);

encodedData inline

template < typename T > void encodedData(
    const std::set < T > & val
);

endCDATA virtual

void endCDATA();

Writes the ]]> string that ends a CDATA section.

endDTD virtual

void endDTD();

Writes the closing characters of a DTD declaration.

endDocument virtual

void endDocument();

Checks that all elements are closed and prints a final newline.

endElement

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().

endEntity

void endEntity(
    const std::string & name
);

Does nothing.

endFragment

void endFragment();

Document fragments are not supported by FIS. Will throw an exception.

endPrefixMapping

void endPrefixMapping(
    const std::string & prefix
);

End the scope of a prefix-URI mapping.

getDocumentVocabulary virtual inline

DocumentVocabulary & getDocumentVocabulary();

Returns the documentVocabulary

getDocumentVocabulary virtual

const DocumentVocabulary & getDocumentVocabulary() const;

Returns the documentVocabulary as a const object

getMaxIndexedStringLength inline

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.

ignorableWhitespace

void ignorableWhitespace(
    const char ch[],
    int start,
    int length
);

Writes whitespace characters by simply passing them to characters().

notationDecl

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!

processingInstruction

void processingInstruction(
    const std::string & target,
    const std::string & data
);

Writes a processing instruction.

setDocumentLocator

void setDocumentLocator(
    const Poco::XML::Locator * loc
);

Unused for Fast Infoset documents.

setDocumentVocabulary virtual inline

void setDocumentVocabulary(
    const DocumentVocabulary & voc
);

Sets the documentVocabulary. Only accepts default vocabularies.

setExternalVocabulary virtual inline

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!

setMaxIndexedStringLength inline

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.

setWriteXMLDeclaration virtual inline

void setWriteXMLDeclaration(
    bool val
);

Set to true if an XML declaration should be written.

skippedEntity

void skippedEntity(
    const std::string & name
);

Does nothing.

startCDATA virtual

void startCDATA();

Writes the [CDATA[ string that begins a CDATA section. Use characters() to write the actual character data.

startDTD

void startDTD(
    const std::string & name,
    const std::string & publicId,
    const std::string & systemId
);

Writes a DTD declaration.

startDocument virtual

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.

startElement

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.

  1. If a qname, but no namespaceURI and localName are given, the qname is taken as element name.
  2. If a namespaceURI and a localName, but no qname is given, and the given namespaceURI has been declared earlier, the namespace prefix for the given namespaceURI together with the localName is taken as element name. If the namespace has not been declared, a prefix in the form "ns1", "ns2", etc. is generated and the namespace is declared with the generated prefix.
  3. If all three are given, and the namespace given in namespaceURI has not been declared, it is declared now. Otherwise, see 2.

startElement

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.

startEntity

void startEntity(
    const std::string & name
);

Does nothing.

startFragment

void startFragment();

Document fragments are not supported by Fast Infoset. Will throw an exception.

startPrefixMapping

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.

unparsedEntityDecl

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!

addAttributes protected

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,

addNamespaceAttributes protected

void addNamespaceAttributes(
    AttributeMap & attributeMap
);

Checks which namespaces are new in the current state and returns them in the AttributeMap.

declareAttributeNamespaces protected

void declareAttributeNamespaces(
    const Poco::XML::Attributes & attributes
);

Declares the namespaces.

handleEncodedData protected

void handleEncodedData();

Serializes any encoded character data, if present.

handleNamespaces protected

void handleNamespaces(
    const Poco::XML::Attributes & attributes,
    const std::string & elementNamespaceURI,
    AttributeMap & nsAttributeMap,
    AttributeValues & attributeVal
);

Handles namespaces.

nameToString protected

const std::string & nameToString(
    const std::string & localName,
    const std::string & qname
) const;

Returns either the localname of the qname.

newPrefix protected

std::string newPrefix();

Creates a new prefix.

Securely control IoT edge devices from anywhere   Connect a Device