XML: complete merge from 1.4.2

This commit is contained in:
Marian Krivos
2011-09-14 14:34:31 +00:00
parent 189695f9c3
commit 16ff8caf6b
59 changed files with 5219 additions and 474 deletions

View File

@@ -40,7 +40,11 @@
#include "Poco/XML/XML.h"
#if defined(POCO_UNBUNDLED)
#include <expat.h>
#else
#include "Poco/XML/expat.h"
#endif
#include "Poco/XML/XMLString.h"
#include "Poco/XML/XMLStream.h"
#include "Poco/SAX/Locator.h"
@@ -158,12 +162,32 @@ public:
void setErrorHandler(ErrorHandler* pErrorHandler);
/// Allow an application to register an error event handler.
ErrorHandler* getErrorHandler() const;
/// Return the current error handler.
void parse(InputSource* pInputSource);
/// Parse an XML document from the given InputSource.
ErrorHandler* getErrorHandler() const;
/// Return the current error handler.
void setEnablePartialReads(bool flag = true);
/// Enable or disable partial reads from the input source.
///
/// This is useful for parsing XML from a socket stream for
/// a protocol like XMPP, where basically single elements
/// are read one at a time from the input source's stream, and
/// following elements depend upon responses sent back to
/// the peer.
///
/// Normally, the parser always reads blocks of PARSE_BUFFER_SIZE
/// at a time, and blocks until a complete block has been read (or
/// the end of the stream has been reached).
/// This allows for efficient parsing of "complete" XML documents,
/// but fails in a case such as XMPP, where only XML fragments
/// are sent at a time.
bool getEnablePartialReads() const;
/// Returns true if partial reads are enabled (see
/// setEnablePartialReads()), false otherwise.
void parse(InputSource* pInputSource);
/// Parse an XML document from the given InputSource.
void parse(const char* pBuffer, std::size_t size);
/// Parses an XML document from the given buffer.
@@ -187,12 +211,18 @@ protected:
void parseByteInputStream(XMLByteInputStream& istr);
/// Parses an entity from the given stream.
void parseCharInputStream(XMLCharInputStream& istr);
/// Parses an entity from the given stream.
void parseCharInputStream(XMLCharInputStream& istr);
/// Parses an entity from the given stream.
std::streamsize readBytes(XMLByteInputStream& istr, char* pBuffer, std::streamsize bufferSize);
/// Reads at most bufferSize bytes from the given stream into the given buffer.
void handleError(int errorNo);
/// Throws an XMLException with a message corresponding
/// to the given Expat error code.
std::streamsize readChars(XMLCharInputStream& istr, XMLChar* pBuffer, std::streamsize bufferSize);
/// Reads at most bufferSize chars from the given stream into the given buffer.
void handleError(int errorNo);
/// Throws an XMLException with a message corresponding
/// to the given Expat error code.
void parseExternal(XML_Parser extParser, InputSource* pInputSource);
/// Parse an XML document from the given InputSource.
@@ -249,12 +279,13 @@ private:
char* _pBuffer;
bool _encodingSpecified;
XMLString _encoding;
bool _expandInternalEntities;
bool _externalGeneralEntities;
bool _externalParameterEntities;
NamespaceStrategy* _pNamespaceStrategy;
EncodingMap _encodings;
ContextStack _context;
bool _expandInternalEntities;
bool _externalGeneralEntities;
bool _externalParameterEntities;
bool _enablePartialReads;
NamespaceStrategy* _pNamespaceStrategy;
EncodingMap _encodings;
ContextStack _context;
EntityResolver* _pEntityResolver;
DTDHandler* _pDTDHandler;
@@ -337,6 +368,12 @@ inline ErrorHandler* ParserEngine::getErrorHandler() const
}
inline bool ParserEngine::getEnablePartialReads() const
{
return _enablePartialReads;
}
} } // namespace Poco::XML

View File

@@ -71,21 +71,9 @@
// Automatically link XML library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(XML_EXPORTS)
#if defined(POCO_DLL)
#if defined(_DEBUG)
#pragma comment(lib, "PocoXMLd.lib")
#else
#pragma comment(lib, "PocoXML.lib")
#endif
#else
#if defined(_DEBUG)
#pragma comment(lib, "PocoXMLmtd.lib")
#else
#pragma comment(lib, "PocoXMLmt.lib")
#endif
#endif
#endif
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(XML_EXPORTS)
#pragma comment(lib, "PocoXML" POCO_LIB_SUFFIX)
#endif
#endif

View File

@@ -83,14 +83,29 @@ class XML_API XMLWriter: public ContentHandler, public LexicalHandler, public DT
/// prefixes in the form ns1, ns2, etc.
{
public:
enum Options
{
CANONICAL = 0x00, /// do not write an XML declaration
WRITE_XML_DECLARATION = 0x01, /// write an XML declaration
PRETTY_PRINT = 0x02 /// pretty-print XML markup
};
enum Options
{
CANONICAL = 0x00,
/// Do not write an XML declaration (default).
XMLWriter(XMLByteOutputStream& str, int options);
CANONICAL_XML = 0x01,
/// Enables basic support for Canonical XML:
/// - do not write an XML declaration
/// - do not use special empty element syntax
/// - set the New Line character to NEWLINE_LF
WRITE_XML_DECLARATION = 0x02,
/// Write an XML declaration.
PRETTY_PRINT = 0x04,
/// Pretty-print XML markup.
PRETTY_PRINT_ATTRIBUTES = 0x08
/// Write each attribute on a separate line.
/// PRETTY_PRINT must be specified as well.
};
XMLWriter(XMLByteOutputStream& str, int options);
/// Creates the XMLWriter and sets the specified options.
///
/// The resulting stream will be UTF-8 encoded.
@@ -123,12 +138,23 @@ public:
/// * NEWLINE_LF (Unix),
/// * NEWLINE_CR (Macintosh)
const std::string& getNewLine() const;
/// Returns the line ending currently in use.
const std::string& getNewLine() const;
/// Returns the line ending currently in use.
// ContentHandler
void setDocumentLocator(const Locator* loc);
/// Currently unused.
void setIndent(const std::string& indent);
/// Sets the string used for one indentation step.
///
/// The default is a single TAB character.
/// The given string should only contain TAB or SPACE
/// characters (e.g., a single TAB character, or
/// two to four SPACE characters).
const std::string& getIndent() const;
/// Returns the string used for one indentation step.
// ContentHandler
void setDocumentLocator(const Locator* loc);
/// Currently unused.
void startDocument();
/// Writes a generic XML declaration to the stream.
@@ -260,12 +286,13 @@ protected:
void writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname);
void writeMarkup(const std::string& str) const;
void writeXML(const XMLString& str) const;
void writeXML(XMLChar ch) const;
void writeNewLine() const;
void writeIndent() const;
void writeName(const XMLString& prefix, const XMLString& localName);
void writeXMLDeclaration();
void closeStartTag();
void writeXML(XMLChar ch) const;
void writeNewLine() const;
void writeIndent() const;
void writeIndent(int indent) const;
void writeName(const XMLString& prefix, const XMLString& localName);
void writeXMLDeclaration();
void closeStartTag();
void declareAttributeNamespaces(const Attributes& attributes);
void addNamespaceAttributes(AttributeMap& attributeMap);
void addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI);
@@ -302,18 +329,23 @@ private:
bool _inInternalDTD;
bool _contentWritten;
bool _unclosedStartTag;
ElementStack _elementStack;
NamespaceSupport _namespaces;
int _prefix;
ElementStack _elementStack;
NamespaceSupport _namespaces;
int _prefix;
bool _nsContextPushed;
std::string _indent;
static const std::string MARKUP_QUOTENC;
static const std::string MARKUP_APOSENC;
static const std::string MARKUP_AMPENC;
static const std::string MARKUP_LTENC;
static const std::string MARKUP_GTENC;
static const std::string MARKUP_LT;
static const std::string MARKUP_GT;
static const std::string MARKUP_SLASHGT;
static const std::string MARKUP_QUOTENC;
static const std::string MARKUP_APOSENC;
static const std::string MARKUP_AMPENC;
static const std::string MARKUP_LTENC;
static const std::string MARKUP_GTENC;
static const std::string MARKUP_TABENC;
static const std::string MARKUP_CRENC;
static const std::string MARKUP_LFENC;
static const std::string MARKUP_LT;
static const std::string MARKUP_GT;
static const std::string MARKUP_SLASHGT;
static const std::string MARKUP_LTSLASH;
static const std::string MARKUP_COLON;
static const std::string MARKUP_EQQUOT;