domwriterimpl.hpp
来自「IBM的解析xml的工具Xerces的源代码」· HPP 代码 · 共 497 行 · 第 1/2 页
HPP
497 行
* </dl></dd> * <dt> * <code>"discard-default-content"</code></dt> * <dd> * <dl> * <dt><code>true</code></dt> * <dd>[required] (default * ) Use whatever information available to the implementation (i.e. XML * schema, DTD, the <code>specified</code> flag on <code>Attr</code> nodes, * and so on) to decide what attributes and content should be serialized or * not. Note that the <code>specified</code> flag on <code>Attr</code> nodes * in itself is not always reliable, it is only reliable when it is set to * <code>false</code> since the only case where it can be set to * <code>false</code> is if the attribute was created by a Level 1 * implementation. </dd> * <dt><code>false</code></dt> * <dd>[required] Output all attributes and * all content. </dd> * </dl></dd> * <dt><code>"format-canonical"</code></dt> * <dd> * <dl> * <dt><code>true</code></dt> * <dd>[optional] * This formatting writes the document according to the rules specified in . * Setting this feature to true will set the feature "format-pretty-print" * to false. </dd> * <dt><code>false</code></dt> * <dd>[required] (default) Don't canonicalize the * output. </dd> * </dl></dd> * <dt><code>"format-pretty-print"</code></dt> * <dd> * <dl> * <dt><code>true</code></dt> * <dd>[optional] * Formatting the output by adding whitespace to produce a pretty-printed, * indented, human-readable form. The exact form of the transformations is * not specified by this specification. Setting this feature to true will * set the feature "format-canonical" to false. </dd> * <dt><code>false</code></dt> * <dd>[required] * (default) Don't pretty-print the result. </dd> * </dl></dd> * </dl> * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20011025'>Document Object Model (DOM) Level 3 Abstract Schemas and Load * and Save Specification</a>. */#ifndef DOMWriterImpl_HEADER_GUARD_#define DOMWriterImpl_HEADER_GUARD_#include <xercesc/dom/DOM.hpp>#include <xercesc/dom/DOMWriter.hpp>#include <xercesc/util/XMLDOMMsg.hpp>#include <xercesc/util/RefHashTableOf.hpp>#include <xercesc/util/RefVectorOf.hpp>XERCES_CPP_NAMESPACE_BEGINclass CDOM_EXPORT DOMWriterImpl:public XMemory, public DOMWriter {public: /** @name Constructor and Destructor */ //@{ /** * Constructor. */ DOMWriterImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); /** * Destructor. */ ~DOMWriterImpl(); //@} /** @name Inplementation of Abstract interface */ virtual bool canSetFeature(const XMLCh* const featName , bool state) const; virtual void setFeature(const XMLCh* const featName , bool state); virtual bool getFeature(const XMLCh* const featName) const; virtual void setEncoding(const XMLCh* const encoding); virtual const XMLCh* getEncoding() const; virtual void setNewLine(const XMLCh* const newLine); virtual const XMLCh* getNewLine() const; virtual void setErrorHandler(DOMErrorHandler *errorHandler); virtual DOMErrorHandler* getErrorHandler() const; virtual void setFilter(DOMWriterFilter *filter); virtual DOMWriterFilter* getFilter() const; virtual bool writeNode(XMLFormatTarget* const destination , const DOMNode &nodeToWrite); virtual void release(); /** * The caller is responsible for the release of the returned string */ virtual XMLCh* writeToString(const DOMNode &nodeToWrite); //@}private: /** unimplemented copy ctor and assignment operator */ DOMWriterImpl(const DOMWriterImpl&); DOMWriterImpl & operator = (const DOMWriterImpl&); /** helper **/ void initSession(const DOMNode* const); void processNode(const DOMNode* const); void procCdataSection(const XMLCh* const nodeValue , const DOMNode* const nodeToWrite , int level); void procUnrepCharInCdataSection(const XMLCh* const nodeValue , const DOMNode* const nodeToWrite , int level);protected: /** * Overidden by derived classes to extend the abilities of the standard writer * always returns false in the default implementation * @return true if the method deals with nodeToWrite */ virtual bool customNodeSerialize(const DOMNode* const nodeToWrite, int level); DOMNodeFilter::FilterAction checkFilter(const DOMNode* const) const; bool checkFeature(const XMLCh* const featName , bool state , int& featureId) const; bool reportError(const DOMNode* const errorNode , DOMError::ErrorSeverity errorType , const XMLCh* const errorMsg); bool reportError(const DOMNode* const errorNode , DOMError::ErrorSeverity errorType , XMLDOMMsg::Codes toEmit); bool canSetFeature(const int featureId , bool val) const; void setFeature(const int featureId , bool val); bool getFeature(const int featureId) const; void printNewLine(); void setURCharRef(); void printIndent(int level) const; //does the actual work for processNode while keeping track of the level void processNode(const DOMNode* const nodeToWrite, int level); void processBOM(); // ----------------------------------------------------------------------- // Private data members // // fFeatures // // fEncoding // own it // // fNewLine // own it // // fErrorHandler // don't own it // // fFilter // don't own it // // fDocumentVersion // The XML Version of the document to be serialized. // // fEncodingUsed (session var) // the actual encoding used in WriteNode(), // it does not own any data(memory). // // fNewLineUsed (session var) // the actual "end of line" sequence used in WriteNode(), // it does not own any data(memory). // // fFormatter (session var) // the formatter used in WriteNode() // // fErrorCount // the count of error encountered in the serialization, // which neither the error handler, nor the serializer itself, // treat as fatal. And the serializer will return true/false // based on this value. // // fCurrentLine // the current line. Used to track the line number the current // node begins on // // ----------------------------------------------------------------------- int fFeatures; XMLCh *fEncoding; XMLCh *fNewLine; DOMErrorHandler *fErrorHandler; DOMWriterFilter *fFilter; const XMLCh *fDocumentVersion; //session vars const XMLCh *fEncodingUsed; const XMLCh *fNewLineUsed; XMLFormatter *fFormatter; int fErrorCount; int fCurrentLine; RefVectorOf< RefHashTableOf<XMLCh> >* fNamespaceStack; MemoryManager* fMemoryManager;};inline void DOMWriterImpl::setFeature(const int featureId , bool val){ (val)? fFeatures |= (1<<featureId) : fFeatures &= ~(1<<featureId);};inline bool DOMWriterImpl::getFeature(const int featureId) const{ return ((fFeatures & ( 1<<featureId )) != 0) ? true : false;};inline void DOMWriterImpl::setURCharRef(){ fFormatter->setUnRepFlags(XMLFormatter::UnRep_CharRef);}XERCES_CPP_NAMESPACE_END#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?