VB读取XML文件,selectNodes获取节点属性_vb 读取xml-程序员宅基地

技术标签: VBA 开发  selectNodes  selectsingleNode  vb  

      VB读取XML文件,通过selectNodes,selectSingleNode获取 XML文件节点内容,将获取的内容赋值给类的属性。


被读取的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<issues total_count="1" offset="0" limit="25" type="array">
    <issue>
        <id>3344</id>
        <project id="49" name="text xml" />
        <tracker id="9" name="支持" />
        <status id="5" name="已确认" />
        <priority id="2" name="普通" />
        <author id="34" name="author1" />
        <assigned_to id="34" name="author1" />
        <subject>test1-支持任务第一个</subject>
        <description></description>
        <start_date>2015-04-01</start_date>
        <due_date>2015-04-07</due_date>
        <done_ratio>100</done_ratio>
        <is_private>false</is_private>
        <estimated_hours>8.0</estimated_hours>
        <custom_fields type="array">
            <custom_field id="3" name="作业者">
                <value>34</value>
            </custom_field>
            <custom_field id="4" name="确认者">
                <value>14</value>
            </custom_field>
        </custom_fields>
        <created_on>2015-04-10T02:23:23Z</created_on>
        <updated_on>2015-04-27T05:54:31Z</updated_on>
        <closed_on>2015-04-10T07:29:58Z</closed_on>
    </issue>
</issues>


vb读入代码:

Public Function getIssuesCollection() As Collection
     Set xdoc = CreateObject("Microsoft.XMLDOM")
	'异步标志(true时,不等待xml文件读入完成,直接执行后续代码;false时,等待xml文件读入完成后,再执行后续代码)
	xdoc.async = False
    xdoc.Load ("E:\xmlTemp\issue.xml")
    Set issues = xdoc.SelectNodes("issues/issue")
    
    For Each issue In issues
        Set crtIssue = New cls_Issue
        crtIssue.IssueId = issue.SelectSingleNode("id").Text
        crtIssue.ProjectId = issue.SelectSingleNode("project").Attributes.Item(0).Text
        crtIssue.ProjectName = issue.SelectSingleNode("project").Attributes.Item(1).Text
        crtIssue.TrackerName = issue.SelectSingleNode("tracker").Attributes.Item(1).Text
        crtIssue.Status = issue.SelectSingleNode("status").Attributes.Item(1).Text
        crtIssue.Priority = issue.SelectSingleNode("priority").Attributes.Item(1).Text
        crtIssue.Author = issue.SelectSingleNode("author").Attributes.Item(1).Text
        If Not issue.SelectSingleNode("assigned_to") Is Nothing Then
            crtIssue.Assigned_to = issue.SelectSingleNode("assigned_to").Attributes.Item(1).Text
        End If
        crtIssue.Subject = issue.SelectSingleNode("subject").Text
        crtIssue.StartDate = issue.SelectSingleNode("start_date").Text
        crtIssue.DueDate = issue.SelectSingleNode("due_date").Text
        
        If Not issue.SelectSingleNode("estimated_hours") Is Nothing Then
            crtIssue.Estimated_hours = issue.SelectSingleNode("estimated_hours").Text
        End If
        If Not issue.SelectSingleNode("done_ratio") Is Nothing Then
            crtIssue.Done_ratio = issue.SelectSingleNode("done_ratio").Text
        End If
        If Not issue.SelectSingleNode("parent") Is Nothing Then
            crtIssue.ParentId = issue.SelectSingleNode("parent").Attributes.Item(0).Text
        End If
        
        Set custom_fields = issue.SelectNodes("custom_fields/custom_field")
        For Each custom_field In custom_fields
            'when  id is user checked
            If checked_custom_fields.Exists(custom_field.Attributes.Item(0).Text) Then
                Set cfield = checked_custom_fields.Item(custom_field.Attributes.Item(0).Text)
                Set cloneCfield = cfield.clone
                cloneCfield.value = custom_field.Text
                ' to add id/cField
                crtIssue.mCustomFields.Add custom_field.Attributes.Item(0).Text, cloneCfield
                'Debug.Print cfield.value
            End If
        Next

        allIssues.Add crtIssue
    Next

End Function



版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/psp0001060/article/details/49205891

智能推荐

h5 ios系统在微信浏览器兼容问题导致的事件错乱问题_微信浏览器ios h5获取麦克风权限无效-程序员宅基地

文章浏览阅读1.5k次。参考https://www.jianshu.com/p/98adc64aeb61/_微信浏览器ios h5获取麦克风权限无效

仿着锤子科技官网进行的一个angular4.0项目~~~-程序员宅基地

文章浏览阅读1k次。关于项目关于angular4的一个项目项目功能还没完全实现 代码我放在了GitHub上

基于阿里云容器镜像服务加速K8S镜像下载_kubectl 阿里云下载-程序员宅基地

文章浏览阅读4.5k次。简单说明:部署K8S最大的难题是镜像下载可以使用阿里云容器镜像服务由海外机器构建国内同时可以使用阿里云的镜像加速器加速镜像下载仅需要将含有相关镜像的Dockerfile提交到阿里云即可申请云Code代码托管账号作为代码源可以绑定到阿里云镜像仓库的代码托管服务有很多,这里选用云Code登陆阿里云:https://www.aliyun.com打开云Code账户设置:https:/..._kubectl 阿里云下载

Aptina MT9M114 1.26M camera spec 学习_mt9m114点亮代码-程序员宅基地

文章浏览阅读1.5k次。MT9M114是出自ON半导体公司的CMOS (CMOS与CCD的区别) digital image sensor, active-pixel array是1296 (H) × 976 (V)=1.26Mp.关键参数 Parameter Typical Value 中文解释 Optical Format 1/6-inch ..._mt9m114点亮代码

计算机科学与技术在军中的应用,计算机科学技术的应用及发展趋势-程序员宅基地

文章浏览阅读2.5k次。114 ?电子技术与软件工程 Electronic Technology & Software Engineering计算机技术应用? the Application of Computer Technology【关键词】计算机科学技术 应用 发展趋势计算机科学技术的发明是人类社会史上的重要财富之一,并经过不断的改革创新,使得计算机科学技术在人们的生活中得到广泛应用。并涉及到社会上各个领域...

Android画板的实现-程序员宅基地

文章浏览阅读87次。这是一个常见的画板功能,常用于画画和手写输入等等,今天就教大家实现这个小功能,这个功能还是比较简单的,只有一个Java文件先看效果图布局代码,只有三个按钮和一张图片<?xml version="1.0" encoding="utf-8"?><LinearLayout ="http://schemas.android.com/a..._androi画板代码

随便推点

r语言显示找不到read_html,R语言答疑:txt文件无法被R正确读入-程序员宅基地

文章浏览阅读1.6k次。今天来解答一个网友的疑惑,或许你也曾遇到过这个问题噢~R语言中,txt无法正确的读入的可能性有很多种。有位网友提供的一个无法正确读入的文本文件,使用记事本打开,看起来一切正确(见图片)。但读入的时候,报错如下。>read.table('1.txt')Error intype.convert(data[], as.is = as.is, dec = dec, numerals = numera..._error in read_html(url) : 没有"read_html"这个函数

恒生电子工作经历-程序员宅基地

文章浏览阅读1w次。2012年7月开始正式入职恒生

ZYNQ接口分析_zynq的b35接口是什么意思-程序员宅基地

文章浏览阅读4.1k次,点赞3次,收藏21次。有人说,自动生成工程时,有可能将所有axi-lite连接到了zynq_us的m_axi_hpm0_lpd上,好像默认lpd不能用,需要开启时钟、电源?还是什么使能信号才可以用,所以会导致sdk中的例子不能直接访问pl上的外设,并导致cpu挂死。可以将lpd改为fpd,这样应该就没问题了。是否是这个原因,未确认,还有可能是“ID转换”无法(2条消息)2. ZCU102 HDMI Demo【P..._zynq的b35接口是什么意思

linux系统挂载光盘设备,文件系统的挂载、usb设备光盘的使用-程序员宅基地

文章浏览阅读389次。一、 文件系统的挂载mount:1. 挂载命令mount使用:(1)挂载: 将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件访问入口的行为,挂载点下原有文件在挂载完成后会被临时隐藏(2) 卸载:为解除此关联关系的过程,可使用设备,也可以使用挂载点(3) 用法:mount 设备 挂载点设备类型:1) 可以使用设备文件如/dev/sda;2) 可以使..._linux 挂载光盘 df

openoffice module or group “X Window System“ is not available_module or group 'x window system' is not available-程序员宅基地

文章浏览阅读6.7k次,点赞2次,收藏10次。openoffice 安装最后一步启动提示"X Window System" is not available 图形化窗口_module or group 'x window system' is not available.

基于MATLAB的FIR滤波器的设计及应用(图像_matlab如何绘制fir滤波器的幅值曲线-程序员宅基地

文章浏览阅读945次,点赞23次,收藏25次。利用等波纹最佳逼近准则设计线性相位FIR数字滤波器数学模型的建立及其求解算法的推导复杂,所以求解必须借助MATLAB信号处理工具箱函数remezord和remez,只要简单的调用这两个函数就可以完成线性相位FIR数字滤波器的等波纹最佳逼近设计。1.该课题设计是先画出原始图像,然后画出加噪图像,然后由各项参数求出单位脉冲响应和其频率响应,再分别用布莱克曼窗函数法和等波纹最佳逼近法画出信号波形和去噪图像,并分析和比较,在分别求出损耗函数。_matlab如何绘制fir滤波器的幅值曲线

推荐文章

热门文章

相关标签