xmltools.h

来自「Xerces-C++应用实例」· C头文件 代码 · 共 115 行

H
115
字号
// ================================================================================
//
//    author:         Rainer Schuster
//
//    created:        09.03.2005 10:18:56
//
//    filename:       xmltools.h
//
//    This code is as it is. You are allowed to use, modify and/or redistribute it freely.
//    I'm not responsible for any errors or damage. Use it at your own risk.
//
// ================================================================================





#ifndef _XMLTOOLS_H
#define _XMLTOOLS_H


// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------

#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/util/XMLString.hpp>


XERCES_CPP_NAMESPACE_USE

// ============== codesnippet from xerces
// ---------------------------------------------------------------------------
//  This is a simple class that lets us do easy (though not terribly efficient)
//  trancoding of XMLCh data to local code page for display.
// ---------------------------------------------------------------------------
class XStr
{
public :
    // -----------------------------------------------------------------------
    //  Constructors and Destructor
    // -----------------------------------------------------------------------
	
	XStr()
	{
		fLocalForm=NULL;
		fUnicodeForm=NULL;
	}

    XStr(const XMLCh* const toTranscode)
    {
        // Call the private transcoding method
        fLocalForm = XMLString::transcode(toTranscode);
		fUnicodeForm=NULL;
    }

    XStr(const char* const toTranscode)
    {
        // Call the private transcoding method
        fUnicodeForm = XMLString::transcode(toTranscode);
		fLocalForm=NULL;
    }


    ~XStr()
    {
        if (fLocalForm)
		{
			XMLString::release(&fLocalForm);
		}
        if (fUnicodeForm)
		{
			XMLString::release(&fUnicodeForm);
		}
    }


    // -----------------------------------------------------------------------
    //  Getter methods
    // -----------------------------------------------------------------------
    const char* localForm() const
    {
        return fLocalForm;
    }

    const XMLCh* unicodeForm() const
    {
        return fUnicodeForm;
    }


private :
    // -----------------------------------------------------------------------
    //  Private data members
    //
    //  fLocalForm
    //      This is the local code page form of the string.
    // -----------------------------------------------------------------------
    char*   fLocalForm;
    XMLCh*   fUnicodeForm;
};

#define X(str) XStr(str).unicodeForm()
#define XC(str) XStr(str).localForm()


DOMNode *GetFirstNode(const DOMDocument *doc, const char *lpstrName);
bool GetAttributeValue (const DOMNode *nd, const char *lpstrName, char *lpstrValue, int nMaxLen);
bool GetAttributeValue (const DOMNode *nd, const char *lpstrName, long &lValue);
DOMNode *GetFirstSubNode(const DOMNode *nd, const char *lpstrName);
char *XMLDateToDate(const char *lpstrXMLDate);

#endif

⌨️ 快捷键说明

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