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

📄 simplexml.h

📁 symbian s60上的GPS
💻 H
字号:
/*
* ============================================================================
*  Name 	: CSimpleXml from SimpleXml.h
*  Created	: 27/11/2003 by EMCC Software Ltd
*  Description:	Parsing and generation of a simple subset of XML
*  Version	: 1
*  Copyright: EMCC Software Ltd
* ============================================================================
*/

#ifndef __SIMPLEXML_H__
#define __SIMPLEXML_H__

// System includes
#include <e32base.h>

// User includes

// Definitions

const TInt KDefaultMaxXmlElementNesting = 16;

////////////////////////////////
// Character type traits classes
////////////////////////////////

//#if 0
	typedef TDesC8 TXmlDesC;
	typedef TPtrC8 TXmlPtrC;
	typedef TPtr8 TXmlPtr;
	typedef HBufC8 HXmlBufC;
	typedef TText8 TXmlText;
//#else
//	typedef TDesC16 TXmlDesC;
//	typedef TPtrC16 TXmlPtrC;
//	typedef TPtr16 TXmlPtr;
//	typedef HBufC16 HXmlBufC;
//	typedef TText16 TXmlText;
//#endif

// Forward declarations of classes defined further down this file

class CXmlAttribute;
class CXmlChunk;
class CXmlText;
class CXmlElement;


/**
* CSimpleXml
*
*/


class CSimpleXml : public CBase
  	{

public:		// Definitions
	enum TPanic
		{
		EPanicNoRootElement,
		EPanicNoElementName,
		EPanicNoAttributeKeyword,
		EPanicNoAttributeValue,
		EPanicChunkNotElement,
		EPanicChunkNotText,
		EPanicBadNesting,
		};

public:
	/**
	* Two-phase construction
	*/
	static CSimpleXml* NewL();
	static CSimpleXml* NewLC();

	/**
	* First-phase constructor
	*/
	CSimpleXml();

	/**
	* Second-phase constructor.
	*/
	virtual void ConstructL();

	/**
	* Destructor.
	*/
	virtual ~CSimpleXml();

	/**
	* Parse
	* Generates an internal representation of the input XML source
	*/
	virtual void ParseL(const TXmlDesC &aXml);

	/**
	* RootElement
	* Accessor for the root element
	*/

	virtual CXmlElement& RootElement() const;

	/**
	* Reset
	* Clear out the internal XML representation
	*/

	virtual void Reset();

	/**
	* CreateRootElementL
	* Create a new root element (replaces any existing data)
	*/

	virtual CXmlElement& CreateRootElementL(const TXmlDesC &aName);

	/**
	* Output our XML
	*/
	virtual HXmlBufC *OutputLC();
	virtual HXmlBufC *OutputL();

	/**
	* Panic
	* Public, but only intended for use by our helper classes
	*/
	static void Panic(TPanic aPanic);

private:	// definitions

	enum TChunkType
		{
		EChunkXmlDeclaration,
		EChunkXmlElement,
		EChunkXmlElementEnd,
		EChunkText,
		};

private:
	/**
	* Helper methods
	*/
	TChunkType FindNextChunkL();
	void GetXmlDeclarationL();
	void GetXmlElementL(CXmlElement &aElement);
	void GetNameL(HXmlBufC*& aName);
	TBool GetPossibleAttributeL(RPointerArray<CXmlAttribute >& aAttributeList);
	void GetTextL(HXmlBufC*& aText, TChar aQuote = 0);
	void OutputL(CXmlElement& aElement);
	void OutputL(const TXmlDesC& aDesc);
	void OutputL(TXmlText aText);
	void ConvOutputL(const TXmlDesC& aDesc);

private:	// data
	TXmlPtrC iAllXml;					// the whole of the XML being parsed
	TXmlPtrC iCurXml;					// the XML from current position to end
	CXmlElement *iRootElement;
	RPointerArray<CXmlAttribute > iXmlAttributes;	// attributes in the XML declaration

	// Variables used during recursive parsing and output processing
	CArrayFixSeg<TXmlText> *iTempBuf;	// output buffer has been made a member variable for the
										// purposes of saving stack space when making recursive calls
	TInt iNesting;						// current XML element nesting level
	TInt iMaxNesting;					// maximum allowed nesting level
	};

/**
* CXmlAttribute
* The internal representation of an XML attribute
*/


class CXmlAttribute : public CBase
	{
	friend class CSimpleXml;
	friend class CXmlElement;

	/**
	* Only needs one constructor
	*/
private:							// only constructed by CSimpleXml
	CXmlAttribute();

	/**
	* Destructor.
	*/
public:
	virtual ~CXmlAttribute();

	/**
	* Accessor for keyword
	*/
	virtual const TXmlDesC& Keyword() const;

	/**
	* Accessor for value
	*/
	virtual const TXmlDesC& Value() const;

	/**
	* Add an as-yet-empty attribute to an attribute list
	*/
private:								// for use by friend classes only
	static CXmlAttribute& AddAttributeToListL(RPointerArray<CXmlAttribute >& aAttributeList);

private:	// Data
	HXmlBufC *iKeyword;
	HXmlBufC *iValue;
	};

/**
* CXmlChunk
* A "chunk": the basic building block of XML data - may either be a section of
* text or a complete element (CXmlText or CXmlElement classes, derived from this)
*/


	enum TType
	{
	EElement,
	EText
	};

	enum TXMLType
	{
	EXMLElement,
	EXMLText
	};

class CXmlChunk : public CBase
	{

public:



	/**
	* Only needs one constructor
	*/
	CXmlChunk();

	/**
	* Destructor.
	*/
	virtual ~CXmlChunk();

	/**
	* Get type
	*/
	virtual TType Type() const = 0;

	/**
	* Element
	* Accessor for the CXmlElement derived object
	*/

	virtual CXmlElement& Element();

	/**
	* Text
	* Accessor for the CXmlText derived object
	*/

	virtual CXmlText& Text();

private:	// Data

	};

/**
* CXmlElement
* The internal representation of an XML element
*/


class CXmlElement : public CXmlChunk
	{
	friend class CSimpleXml;

	/**
	* Only needs one constructor
	*/
private:							// only constructed by CSimpleXml
	CXmlElement();

	/**
	* Destructor.
	*/
public:
	virtual ~CXmlElement();

	/**
	* Get type
	*/
	virtual TType Type() const;

	/**
	* Accessor for name
	*/
	virtual const TXmlDesC& Name() const;

	/**
	* Get number of attributes
	*/
	virtual TInt AttributeCount() const;

	/**
	* Accessor for an attribute
	*/
	virtual CXmlAttribute& Attribute(TInt aAttribNum);

	/**
	* Get number of chunks
	*/
	virtual TInt ChunkCount() const;

	/**
	* Accessor for a chunk
	*/
	virtual CXmlChunk& Chunk(TInt chunkNum);

	/**
	* Add an attribute
	*/
	virtual CXmlAttribute& AddAttributeL(const TXmlDesC& aKeyword, const TXmlDesC& aValue);

	/**
	* Add an element
	*/
	virtual CXmlElement& AddElementL(const TXmlDesC& aName);

	/**
	* Add a chunk of text
	*/
	virtual CXmlText& AddTextL(const TXmlDesC& aText);

private:	// Methods
	/**
	* Add an as-yet-unnamed element
	*/
	CXmlElement& AddElementL();

	/**
	* Add an as-yet empty chunk of text
	*/
	CXmlText& AddTextL();

	/**
	* Helper method to add an untyped chunk
	*/
	void AddChunkL(CXmlChunk *aNewChunk);

private:	// Data
	RPointerArray<CXmlAttribute > iAttributes;
	RPointerArray<CXmlChunk > iChunks;
	HXmlBufC *iName;
	};


/**
* CXmlText
* The internal representation of an XML text chunk
*/


class CXmlText : public CXmlChunk
	{
	friend class CSimpleXml;
	friend class CXmlElement;

	/**
	* Only needs one constructor
	*/
private:							// only constructed by CXmlElement
	CXmlText();

	/**
	* Destructor.
	*/
public:
	virtual ~CXmlText();

	/**
	* Get type
	*/
	virtual TType Type() const;

	/**
	* Accessor for the contained text
	*/
	virtual const TXmlDesC& Contents();

private:	// Data
	HXmlBufC *iText;
	};

// Following statement no-oped to allow the SimpleXml functionality to be
// exported from a DLL without the need to expose the contents of the .inl
// file to the client.
// #include "SimpleXml.inl"

#endif // __SIMPLEXML_H__

⌨️ 快捷键说明

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