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

📄 xmltools.cpp

📁 Xerces-C++应用实例
💻 CPP
字号:
// ================================================================================
//
//    author:         Rainer Schuster
//
//    created:        09.03.2005 10:19:07
//
//    filename:       xmltools.cpp    IMPLEMENTATION
//
//    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.
//
// ================================================================================



#include "stdafx.h"

#include <xercesc/dom/DOMNamedNodeMap.hpp>

#include "xmltools.h"

	
DOMNode *GetFirstNode(const DOMDocument *doc, const char *lpstrName)
{
	DOMNodeList *nd=doc->getElementsByTagName(X(lpstrName));
	if (nd->getLength()>0)
	{
		return nd->item(0);
	}
	else
	{
		return NULL;
	}
}

bool GetAttributeValue (const DOMNode *nd, const char *lpstrName, char *lpstrValue, int nMaxLen)
{
	memset (lpstrValue,0,nMaxLen);
	
	if (nd)
	{
		DOMNode *stnd=nd->getAttributes()->getNamedItem(X(lpstrName));
		if (stnd)
		{
			strcpy (lpstrValue,XC(stnd->getNodeValue()));
			return true;
		}
	}

	return false;
}

bool GetAttributeValue (const DOMNode *nd, const char *lpstrName, long &lValue)
{
	if (nd)
	{
		DOMNamedNodeMap *attributes = nd->getAttributes();
		if( attributes )
		{
			DOMNode *stnd=attributes->getNamedItem(X(lpstrName));
			if (stnd)
			{
				lValue = atoi( XC(stnd->getNodeValue()) );
				return true;
			}
		}
	}

	return false;
}

DOMNode *GetFirstSubNode(const DOMNode *nd, const char *lpstrName)
{
	DOMNode *rc=NULL;
	DOMNodeList *cndl=nd->getChildNodes();
	
	for (UINT i=0; i<cndl->getLength(); i++)
	{
		DOMNode *p=cndl->item(i);
		if (strcmp (XC(p->getNodeName()),lpstrName)==0)
		{
			rc=p;
		}
	}

	return rc;
}


char *XMLDateToDate(const char *lpstrXMLDate)
{
	// Format YYYY-MM-DD
	// in DD.MM.YYYY
	static char lcReturn[128];
	memset (lcReturn,0,128);
	
	strcpy (lcReturn,lpstrXMLDate+8);
	strcat (lcReturn,".");
	strncat (lcReturn,lpstrXMLDate+5,2);
	strcat (lcReturn,".");
	strncat (lcReturn,lpstrXMLDate,4);
	
	return lcReturn;
}

⌨️ 快捷键说明

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