Poco::FastInfoset

class FastInfosetWriter

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

Description

A FastInfosetWriter serializes ContentHandler/LexicalHandler/DTDHandler events into a binary FISDocument. Note that the writer supports external dictionaries but it doesn't support user defined encodings.

The following example code (taking from the FISWriter sample) shows how the FastInfosetWriter is used to convert an xml file into a FastInfoset document:

std::ifstream input;
input.open("dummy.xml", std::ios::binary);
Poco::XML::InputSource is(input);
std::ifstream output;
output.open("dummy.finf", std::ios::binary);

FastInfosetWriter handler(output);
Poco::XML::SAXParser parser;
parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, true);
parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
parser.setContentHandler(&handler);
parser.setDTDHandler(&handler);
parser.setProperty(Poco::XML::XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&handler));

parser.parse(&is);
// finf file created, try catch around parse is recommended but was ommitted for simplicity

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, characters, comment, dataElement, declareAttributeNamespaces, dwordEncoded, emptyElement, encodedData, endCDATA, endDTD, endDocument, endElement, endEntity, endFragment, endPrefixMapping, getDocumentVocabulary, handleCharacters, handleNamespaces, hexEncoded, ignorableWhitespace, nameToString, newPrefix, notationDecl, processingInstruction, rawCharacters, setDocumentLocator, setDocumentVocabulary, setExternalVocabulary, setWriteXMLDeclaration, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startFragment, startPrefixMapping, unparsedEntityDecl, writeMarkup, writeXML

Inherited Functions: characters, comment, dwordEncoded, encodedData, encodedDataCollection, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, getDocumentVocabulary, hexEncoded, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, setDocumentVocabulary, setExternalVocabulary, setWriteXMLDeclaration, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startPrefixMapping, unparsedEntityDecl

Nested Classes

struct AttributeValue protected

 more...

Types

AttributeMap protected

typedef std::map < Poco::XML::XMLString, Poco::XML::XMLString > AttributeMap;

Maps an attribute namespace prefix to a URI.

AttributeValues protected

typedef std::vector < AttributeValue > AttributeValues;

States

typedef std::vector < State > States;

Enumerations

State

UNINITIALIZED

INDOCUMENT

INELEMENT

INCDATA

INDTD

Constructors

FastInfosetWriter

FastInfosetWriter(
    Poco::XML::XMLByteOutputStream & str
);

Creates the FastInfosetWriter with writeXMLDeclaration set to false. Uses an empty DocumentVocabulary.

The resulting stream will be binary encoded.

FastInfosetWriter

FastInfosetWriter(
    Poco::XML::XMLByteOutputStream & str,
    bool writeXMLDeclaration
);

Creates the FastInfosetWriter and sets the specified options. Uses an empty DocumentVocabulary.

The resulting stream will be binary encoded.

FastInfosetWriter

FastInfosetWriter(
    Poco::XML::XMLByteOutputStream & str,
    bool writeXMLDeclaration,
    const DocumentVocabulary & initialVoc
);

Creates the FastInfosetWriter and sets the specified options.

The resulting stream will be binary encoded.

Destructor

~FastInfosetWriter virtual

~FastInfosetWriter();

Destroys the FastInfosetWriter.

Member Functions

characters

void characters(
    const Poco::XML::XMLChar ch[],
    int start,
    int length
);

Writes XML character data. Quotes, ampersand's, less-than and greater-than signs are escaped, unless a CDATA section has been opened by calling startCDATA().

The characters must be encoded in UTF-8 (if Poco::XML::XMLChar is char) or UTF-16 (if Poco::XML::XMLChar is wchar_t).

characters

void characters(
    const Poco::XML::XMLString & str
);

Writes XML character data. Quotes, ampersand's, less-than and greater-than signs are escaped, unless a CDATA section has been opened by calling startCDATA().

The characters must be encoded in UTF-8 (if Poco::XML::XMLChar is char) or UTF-16 (if Poco::XML::XMLChar is wchar_t).

comment

void comment(
    const Poco::XML::XMLChar ch[],
    int start,
    int length
);

Writes a comment.

dataElement

void dataElement(
    const Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & qname,
    const Poco::XML::XMLString & data,
    const Poco::XML::XMLString & attr1 = Poco::XML::XMLString (),
    const Poco::XML::XMLString & value1 = Poco::XML::XMLString (),
    const Poco::XML::XMLString & attr2 = Poco::XML::XMLString (),
    const Poco::XML::XMLString & value2 = Poco::XML::XMLString (),
    const Poco::XML::XMLString & attr3 = Poco::XML::XMLString (),
    const Poco::XML::XMLString & value3 = Poco::XML::XMLString ()
);

Writes a data element in the form <name attr1="value1"...>data</name>.

dwordEncoded virtual

void dwordEncoded(
    const Poco::XML::XMLString & base64String
);

Accepts as input a string that is the result from a base64 encoding

See also: Poco::FastInfoset::FISContentHandler::dwordEncoded()

emptyElement

void emptyElement(
    const Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & qname
);

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

emptyElement

void emptyElement(
    const Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & 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
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

void encodedData(
    Poco::Int32 value
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

void encodedData(
    Poco::Int64 value
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

void encodedData(
    bool value
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

void encodedData(
    float value
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

void encodedData(
    double value
);

See also: Poco::FastInfoset::FISContentHandler::encodedData()

encodedData virtual

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

See also: Poco::FastInfoset::FISContentHandler::encodedData()

endCDATA virtual

void endCDATA();

Writes the ] string that ends a CDATA section.

See also: Poco::XML::LexicalHandler::endCDATA()

endDTD virtual

void endDTD();

Writes the closing characters of a DTD declaration.

See also: Poco::XML::LexicalHandler::endDTD()

endDocument virtual

void endDocument();

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

See also: Poco::XML::ContentHandler::endDocument()

endElement

void endElement(
    const Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & 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 Poco::XML::XMLString & name
);

Does nothing.

endFragment

void endFragment();

Not supported by FIS. Will throw an exception.

endPrefixMapping

void endPrefixMapping(
    const Poco::XML::XMLString & prefix
);

End the scope of a prefix-URI mapping.

getDocumentVocabulary virtual inline

DocumentVocabulary & getDocumentVocabulary();

Returns the documentVocabulary

See also: Poco::FastInfoset::FISDocumentHandler::getDocumentVocabulary()

getDocumentVocabulary virtual

const DocumentVocabulary & getDocumentVocabulary() const;

Returns the documentVocabulary as a const object

See also: Poco::FastInfoset::FISDocumentHandler::getDocumentVocabulary()

hexEncoded virtual

void hexEncoded(
    const Poco::XML::XMLString & hexString
);

Accepts as input a string consisting of chars '0'-'9' 'A' - 'F', hexString.size() % 2 == 0 must be true

See also: Poco::FastInfoset::FISContentHandler::hexEncoded()

ignorableWhitespace

void ignorableWhitespace(
    const Poco::XML::XMLChar ch[],
    int start,
    int length
);

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

notationDecl

void notationDecl(
    const Poco::XML::XMLString & name,
    const Poco::XML::XMLString * publicId,
    const Poco::XML::XMLString * systemId
);

Writes a notation to the header. startDocument must not have been called yet!

processingInstruction

void processingInstruction(
    const Poco::XML::XMLString & target,
    const Poco::XML::XMLString & data
);

Writes a processing instruction.

rawCharacters

void rawCharacters(
    const Poco::XML::XMLString & str
);

Writes the characters in the given string as they are. The caller is responsible for escaping characters as necessary to produce valid XML.

The characters must be encoded in UTF-8 (if Poco::XML::XMLChar is char) or UTF-16 (if Poco::XML::XMLChar is wchar_t).

setDocumentLocator

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

Currently unused.

setDocumentVocabulary virtual inline

void setDocumentVocabulary(
    const DocumentVocabulary & voc
);

Sets the documentVocabulary. Only accepts default vocabularies.

See also: Poco::FastInfoset::FISDocumentHandler::setDocumentVocabulary()

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!

See also: Poco::FastInfoset::FISDocumentHandler::setExternalVocabulary()

setWriteXMLDeclaration virtual inline

void setWriteXMLDeclaration(
    bool val
);

Set to true if an XML declaration should be written.

See also: Poco::FastInfoset::FISDocumentHandler::setWriteXMLDeclaration()

skippedEntity

void skippedEntity(
    const Poco::XML::XMLString & 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 Poco::XML::XMLString & name,
    const Poco::XML::XMLString & publicId,
    const Poco::XML::XMLString & 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 Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & 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 Poco::XML::XMLString & namespaceURI,
    const Poco::XML::XMLString & localName,
    const Poco::XML::XMLString & qname
);

Writes an XML start element tag with no attributes. See the other startElement() method for more information.

startEntity

void startEntity(
    const Poco::XML::XMLString & name
);

Does nothing.

startFragment

void startFragment();

Not supported by FIS. Will throw an exception.

startPrefixMapping

void startPrefixMapping(
    const Poco::XML::XMLString & prefix,
    const Poco::XML::XMLString & namespaceURI
);

Begin the scope of a prefix-URI Namespace mapping. A namespace declaration is written with the next element.

unparsedEntityDecl

void unparsedEntityDecl(
    const Poco::XML::XMLString & name,
    const Poco::XML::XMLString * publicId,
    const Poco::XML::XMLString & systemId,
    const Poco::XML::XMLString & 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 Poco::XML::XMLString & 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.

handleCharacters protected

void handleCharacters();

Serializes any character data, if present.

handleNamespaces protected

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

Handles namespaces.

nameToString protected

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

Returns either the localname of the qname.

newPrefix protected

Poco::XML::XMLString newPrefix();

Creates a new prefix.

writeMarkup protected

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

Appends the string to the character data

writeXML protected

void writeXML(
    const Poco::XML::XMLString & str
);

Appends the string to the character data

writeXML protected

void writeXML(
    Poco::XML::XMLChar ch
);

Appends a single character to the character data.

Variables

MARKUP_AMPENC static

static const std::string MARKUP_AMPENC;

MARKUP_APOSENC static

static const std::string MARKUP_APOSENC;

MARKUP_GTENC static

static const std::string MARKUP_GTENC;

MARKUP_LTENC static

static const std::string MARKUP_LTENC;

MARKUP_QUOTENC static

static const std::string MARKUP_QUOTENC;