⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eaxp_dom.h

📁 symbian 下的解析xml文件的源代码 个人感觉这个比较简单
💻 H
字号:
/*
 * $Id: eaxp_dom.h,v 1.4 2006/10/20 12:41:21 matti Exp $
 *
 * EAXP - Lightweight XML SAX parser for Symbian Environments
 * Copyright (C) 2004-2006 Matti Dahlbom
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: Matti Dahlbom <matti at 777-team.org>
 */

#ifndef __EAXP_DOM_H
#define __EAXP_DOM_H

#include <e32std.h>

#include "eaxp.h"

const TInt KInitialBufferSize = 4096;
const TInt KBufferSizeIncrement = 4096;

_LIT( KXmlHeader, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\" ?>\n" );
_LIT( KXmlIndent, "  " );

_LIT( KEncAmp, "&amp;" );
_LIT( KEncLt, "&lt;" );
_LIT( KEncGt, "&gt;" );
_LIT( KEncQuot, "&quot;" );
_LIT( KEncApos, "&apos;" );

/** 
 * Notes :
 *
 * In the current release, DOM nodes are only
 * used to construct XML documents in a formal way.<p />
 *
 * TODO: add CDATA / Comment nodetypes!
 */

enum TDomNodeType 
    {
    EDocumentNode = 1,
    EElementNode, 
    ETextNode
    };

/**
 * Abstract base class for all EAXP DOM nodes.<p /> 
 * 
 * @author Matti Dahlbom
 * @version $Name: EAXP_20102006 $, $Revision: 1.4 $
 */
class CDomNodeBase : public CBase,
                     public TDes16Overflow 
    {
    public: // Destructor
        /**
         * Destructor. Recursively destroys all children also.
         */
        IMPORT_C virtual ~CDomNodeBase();

    public: // New methods
        /** 
         * Ownership of the argument is transferred.<p />
         */
        IMPORT_C void AddChildL( CDomNodeBase* iChild );

        /**
         * Leaves with KErrOverflow if not enough space left in the buffer.<p />
         */
        virtual void WriteXmlL( TDes& aBuffer, TInt aDepth ) = 0;

        /**
         * Returns the node type.<p />
         */
        TDomNodeType GetNodeType() { return iNodeType; }

    private: // from TDes16Overflow
        void Overflow( TDes16& aDes );

    protected: // New methods
        void EncodeEntitiesL( TDes& aBuffer, const TDesC& aText );

    protected: // Constructors
        CDomNodeBase( TDomNodeType aNodeType );

    protected: // Data
        RPointerArray<CDomNodeBase> iChildren;
        TDomNodeType iNodeType;

        // friend declarations
        friend class CDomElementNode;
    };

/**
 * Document node.<p /> 
 * 
 * @author Matti Dahlbom
 * @version $Name: EAXP_20102006 $, $Revision: 1.4 $
 */
class CDomDocumentNode : public CDomNodeBase
    {
    public: // Constructors and destructor
        IMPORT_C static CDomDocumentNode* NewLC();
        IMPORT_C virtual ~CDomDocumentNode();

    public: // New methods
        /**
         * Extracts textual representation of the DOM model as XML.<p />
         */
        IMPORT_C HBufC* GetXmlLC();

    protected: // New methods
        virtual void WriteXmlL( TDes& aBuffer, TInt aDepth );

    private: // Constructors
        CDomDocumentNode();
        void ConstructL();

    private: // Data
    };

/**
 * Element node, ie. an XML &lt;tag&gt;.<p />
 *
 * @author Matti Dahlbom
 * @version $Name: EAXP_20102006 $, $Revision: 1.4 $
 */
class CDomElementNode : public CDomNodeBase
    {
    public: // Constructors and destructor
        IMPORT_C static CDomElementNode* NewLC( const TDesC& aName, 
                                                const TDesC& aNamespace = KNullDesC );
        IMPORT_C virtual ~CDomElementNode();

    public: // New methods
        /** 
         * Ownership of the argument is transferred.<p />
         */
        IMPORT_C void AddAttributeL( CAttribute* aAttribute );

        /**
         * Convenience method to add an attribute.<p />
         */
        IMPORT_C void AddAttributeL( const TDesC& aName, 
                                     const TDesC& aNamespace, 
                                     const TDesC& aValue );

    protected: // New methods
        virtual void WriteXmlL( TDes& aBuffer, TInt aDepth );
        void IndentL( TDes& aBuffer, TInt aDepth, TBool aAddNewline = ETrue );

    private: // Constructors
        CDomElementNode();
        void ConstructL( const TDesC& aName, const TDesC& aNamespace );

    private: // Data
        HBufC* iName;
        HBufC* iNamespace;
        RPointerArray<CAttribute> iAttributes;
    };

/**
 * Text node.<p />
 *
 * @author Matti Dahlbom
 * @version $Name: EAXP_20102006 $, $Revision: 1.4 $
 */
class CDomTextNode : public CDomNodeBase
    {
    public: // Constructors and destructor
        IMPORT_C static CDomTextNode* NewLC( const TDesC& aText );
        IMPORT_C virtual ~CDomTextNode();

    protected: // New methods
        virtual void WriteXmlL( TDes& aBuffer, TInt aDepth );

    private: // Constructors
        CDomTextNode();
        void ConstructL( const TDesC& aText );

    private: // Data
        HBufC* iText;
    };

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -