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<vtBandInfo> bandsInfo; };
- 1
- 粉丝: 6
- 资源: 41
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于大数据的压缩包密码破解软件详细文档+全部资料+源码.zip
- 基于大数据、人工智能的招聘大数据分析展示系统——前端可视化详细文档+全部资料+源码.zip
- 基于大数据的图书推荐系统详细文档+全部资料+源码.zip
- 基于电子商城项目,包含:数据库操作(mysql)、Swing界面等详细文档+全部资料+源码.zip
- 基于大数据挖掘的饮食推荐小程序详细文档+全部资料+源码.zip
- 基于豆瓣影视数据(不完整)的影视大数据分析平台。爬虫(影视数据和用户数据),推荐系统(基于用户的协同过滤算法),后台(flask实现的简易后台)。详细文档+全部资料+源码.zip
- 基于多种编程语言开源免费不限制提供生活常用,出行服务,开发工具,金融服务,通讯服务和公益大数据的平台详细文档+全部资料+源码.zip
- 基于开源Litemall电商项目的大数据项目数据仓库(五层)、实时计算和用户画像。大数据平台采用CDH6.3.2(已使用vagrant+ansible脚本化),
- 基于注解和反射Excel的简单、大数据量、基于模板、多sheet页的导入导出详细文档+全部资料+源码.zip
- 基于垃圾短信基于文本内容的识别详细文档+全部资料+源码.zip
- 计算机网络资源文件1111
- 基于云平台的大数据路网流量管控详细文档+全部资料+源码.zip
- Delphi 12 控件之DevExpressVCLProducts-24.2.3.exe.zip
- 政府绿色采购明细数据(2015-2024.3).zip
- 天工CAD软件的测试反馈表
- Springboot3声明式客户端