Library: FastInfoset
Package: XML
Header: Poco/FastInfoset/FastInfosetWriter.h
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
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, 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
typedef std::map < Poco::XML::XMLString, Poco::XML::XMLString > AttributeMap;
Maps an attribute namespace prefix to a URI.
typedef std::vector < AttributeValue > AttributeValues;
typedef std::vector < State > States;
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(
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(
Poco::XML::XMLByteOutputStream & str,
bool writeXMLDeclaration,
const DocumentVocabulary & initialVoc
);
Creates the FastInfosetWriter and sets the specified options.
The resulting stream will be binary encoded.
Destroys the FastInfosetWriter.
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).
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).
void comment(
const Poco::XML::XMLChar ch[],
int start,
int length
);
Writes a comment.
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>.
void dwordEncoded(
const Poco::XML::XMLString & base64String
);
Accepts as input a string that is the result from a base64 encoding
void emptyElement(
const Poco::XML::XMLString & namespaceURI,
const Poco::XML::XMLString & localName,
const Poco::XML::XMLString & qname
);
Writes an empty XML element tag (<elem/>).
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"... />).
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
);
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 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().
void endEntity(
const Poco::XML::XMLString & name
);
Does nothing.
void endFragment();
Not supported by FIS. Will throw an exception.
void endPrefixMapping(
const Poco::XML::XMLString & 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
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
void ignorableWhitespace(
const Poco::XML::XMLChar ch[],
int start,
int length
);
Writes whitespace characters by simply passing them to characters().
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!
void processingInstruction(
const Poco::XML::XMLString & target,
const Poco::XML::XMLString & data
);
Writes a processing instruction.
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).
void setDocumentLocator(
const Poco::XML::Locator * loc
);
Currently unused.
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 setWriteXMLDeclaration(
bool val
);
Set to true if an XML declaration should be written.
void skippedEntity(
const Poco::XML::XMLString & 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 Poco::XML::XMLString & name,
const Poco::XML::XMLString & publicId,
const Poco::XML::XMLString & 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 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.
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.
void startEntity(
const Poco::XML::XMLString & name
);
Does nothing.
void startFragment();
Not supported by FIS. Will throw an exception.
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.
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!
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,
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 handleCharacters();
Serializes any character data, if present.
void handleNamespaces(
const Poco::XML::Attributes & attributes,
const Poco::XML::XMLString & elementNamespaceURI,
AttributeMap & nsAttributeMap,
AttributeValues & attributeVal
);
Handles namespaces.
std::string nameToString(
const Poco::XML::XMLString & localName,
const Poco::XML::XMLString & qname
) const;
Returns either the localname of the qname.
Poco::XML::XMLString newPrefix();
Creates a new prefix.
void writeMarkup(
const std::string & str
);
Appends the string to the character data
void writeXML(
const Poco::XML::XMLString & str
);
Appends the string to the character data
void writeXML(
Poco::XML::XMLChar ch
);
Appends a single character to the character data.
static const std::string MARKUP_AMPENC;
static const std::string MARKUP_APOSENC;
static const std::string MARKUP_GTENC;
static const std::string MARKUP_LTENC;
static const std::string MARKUP_QUOTENC;