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>
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 NextEnd Function总结
以上是内存溢出为你收集整理的VB读取XML文件,selectNodes获取节点属性全部内容,希望文章能够帮你解决VB读取XML文件,selectNodes获取节点属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)