文件名称:xml解析实例
文件大小:60KB
文件格式:RAR
更新时间:2016-01-19 04:32:12
xml解析 示例
#pragma once
#include "xmlhelper/easyxml.hpp"
#include "vtString.h"
#include "vtMathTypes.h"
struct vtBandInfo
{
vtString name;
vtString colorInterpretation;
vtString nodata;
int type;//1为数据波段;2为掩码波段
};
class vtPyramidInfo: public XMLVisitor
{
public:
vtPyramidInfo(void);
~vtPyramidInfo(void);
int WriteToXMLFile(const char* pydFileName);
wstring initName;
int LoadFromXMLFile(const char* pydFileName);
private:
//xml visitor
void startXML()
{
level =0;
bandsInfo.clear();
}
void startElement(const char *name, const XMLAttributes &atts;)
{
level++;
m_currentElementName+=".";
m_currentElementName+=name;
if (m_currentElementName==".vtPyramidInfo.Bands.Band")
{
vtString name = atts.getName(0);
vtString val = atts.getValue(0);
bandinfo.name = val;
}
}
void endElement(const char *name)
{
level--;
if (m_currentElementName==".vtPyramidInfo.Bands.Band")
{
bandsInfo.push_back(bandinfo);
}
else if (m_currentElementName==".vtPyramidInfo.PixelType")
{
sscanf(valueStr, "%d", &pixelType;);
}
else if (m_currentElementName==".vtPyramidInfo.Origin")
{
sscanf(valueStr, "%lf,%lf", origin.xPtr(),origin.yPtr());
}
else if (m_currentElementName==".vtPyramidInfo.FinestResolution")
{
sscanf(valueStr, "%lf,%lf", finestResolution.xPtr(),finestResolution.yPtr());
}
else if (m_currentElementName==".vtPyramidInfo.FinestSize")
{
sscanf(valueStr, "%d,%d",finestSize.xPtr(),finestSize.yPtr());
}
else if (m_currentElementName==".vtPyramidInfo.BlockSize")
{
sscanf(valueStr, "%d,%d", blockSize.xPtr(),blockSize.yPtr());
}
else if (m_currentElementName==".vtPyramidInfo.lzts")
{
sscanf(valueStr, "%lf", &lzts;);
}
else if (m_currentElementName==".vtPyramidInfo.ShareEdge")
{
sscanf(valueStr, "%d", &shareEdge;);
}
else if (m_currentElementName==".vtPyramidInfo.MinLevel")
{
sscanf(valueStr, "%d", &minLevel;);
}
else if (m_currentElementName==".vtPyramidInfo.MaxLevel")
{
sscanf(valueStr, "%d", &maxLevel;);
}
else if (m_currentElementName==".vtPyramidInfo.SpatialReference")
{
SRS = valueStr;
}
else if (m_currentElementName==".vtPyramidInfo.PixelLayout")
{
sscanf(valueStr, "%d",&pixelLayout;);
}
int size = strlen(name)+1;//plus a dot
m_currentElementName = m_currentElementName.Left(m_currentElementName.GetLength()-size);
}
void data(const char* s, int length)
{
vtString typeStr(s,length);
if (m_currentElementName==".vtPyramidInfo.Bands.Band.ColorInterpretation")
{
bandinfo.colorInterpretation = typeStr;
}else if (m_currentElementName==".vtPyramidInfo.Bands.Band.Type")
{
sscanf(typeStr, "%d", &bandinfo;.type);
}else if (m_currentElementName==".vtPyramidInfo.Bands.Band.NoDataVal")
{
bandinfo.nodata = vtString(s,length);
}
else
{
valueStr = typeStr;
}
}
vtString m_currentElementName;
int level;
vtBandInfo bandinfo;
vtString valueStr;
public:
/*
作者 :zjb
创建日期 :16:12:2012 9:58
功能业务说明: pixelType
PIXELTYPEENUM_UNKNOWN = 0, //"未知类型"
PIXELTYPEENUM_BYTE = 1, //"字节" size=1字节
PIXELTYPEENUM_USHORT16 = 2, //"无符号位整数" size=2字节
PIXELTYPEENUM_SHORT16 = 3, //"16位整数" size=2字节
PIXELTYPEENUM_UINT32 = 4, //"无符号位整数" size=4字节
PIXELTYPEENUM_INT32 = 5, //"32位整数" size=4字节
PIXELTYPEENUM_FLOAT32 = 6, //"32位浮点数" size=4字节
PIXELTYPEENUM_DOUBLE64 = 7, //"64位浮点数" size=8字节
PIXELTYPEENUM_CSHORT16 = 8, //"复合位整数" size=2字节*2个
PIXELTYPEENUM_CINT32 = 9, //"复合位整数" size=4字节*2个
PIXELTYPEENUM_CFLOAT32 = 10, //"复合位浮点数" size=4字节*2个
PIXELTYPEENUM_CDOUBLE64 = 11, //"复合位浮点数" size=8字节*2个
PIXELTYPEENUM_TYPECOUNT = 12 //"类型的数目"
*/
int pixelType;
DPoint2 origin;
DPoint2 finestResolution;
IPoint2 finestSize;//最高level的栅格大小
IPoint2 blockSize;
double lzts;
int shareEdge;//是否共享边界
int minLevel;
int maxLevel;
vtString SRS;
/*
作者 :zjb
创建日期 :16:12:2012 9:57
功能业务说明:pixelLayout
PIXELLAYOUTTYPEENUM_BSQ = 0, //Band SeQuential also "BAND":Band sequential format stores information for the image one band at a time. In other words, data for all the pixels for band 1 is stored first, then data for all pixels for band 2, and so on.
PIXELLAYOUTTYPEENUM_BIP = 1, //Band Interleaved by Pixel ,also "PIXEL":Band interleaved by pixel data is similar to BIL data, except that the data for each pixel is written band by band
PIXELLAYOUTTYPEENUM_BIL = 2 //Band Interleaved by Line ,aslo "LINE":Band interleaved by line data stores pixel information band by band for each line, or row, of the image
*/
int pixelLayout;
vector
【文件预览】:
xmlhelper
----hashtable.c(4KB)
----asciitab.h(3KB)
----easyxml.cpp(9KB)
----nametab.h(7KB)
----iasciitab.h(3KB)
----xmltok_impl.h(2KB)
----include()
--------xmltok_impl.c(39KB)
--------xmltok_ns.c(2KB)
----hashtable.h(2KB)
----xmlparse.h(18KB)
----xmlparse.c(87KB)
----xmlrole.c(23KB)
----xmltok.c(37KB)
----exception.cpp(5KB)
----easyxml.hpp(12KB)
----exception.hpp(5KB)
----latin1tab.h(3KB)
----xmldef.h(2KB)
----xmltok.h(11KB)
----utf8tab.h(3KB)
----xmlrole.h(3KB)