VBS 遍历xml---1

上一篇 / 下一篇  2012-07-13 13:30:09 / 个人分类:VBS

Dim strXML, xmlSectionName

 '该行仅为实例,前面为xml文件路径,后面为查找的tag名称
GetXml "http://mfl-int:7401/MFL/getFundDetail/v1.0/REST?

fundID=0010&section=FundInformation,AgMrgBkdSctrDiversificationPct,AssetA

llocation,AssetAllocationOverTime,AssetClassDivPct,AssetBackedSectorDivPc

t,CommodityInstrument,CompByIntrumentPct,CompByQualityPct,CorpSectorDiv,C

ountryDivPct,CreditQuality,CurrencyDivPct,DurationDistribution,FundFacts,

GeoDistribution,HistoricalFundInfo,MajorMarketSector,MaturityDistribution

,OtherGovSectorDiv,PortfolioDiv,RealEstateDivPct,RevenueDiv,StyleMap,FixB

oxStyleMap,SubjectToAMT,Top10Holdings,Top5Issuers,Top5States,PortfolioDat

a,Global,Composition,Disclosure&appCode=NETBENEFITS","RatingsTabSuppressI

nd","FundInformation"

'定义并输出返回的值
RatingsTabSuppressInd =  strXML
Msgbox RatingsTabSuppressInd

Function GetXml (ByVal strXmlFilePath,ByVal xmlNodeName,ByVal

xmlSectionName)

        Dim xmlDoc,xmlRoot
       
        Set xmlDoc = CreateObject("Microsoft.XMLDOM")
        xmlDoc.async = False
        xmlDoc.load strXmlFilePath     
        If xmlDoc.parseError.errorCode <> 0 Then
                MsgBox "XML文件格式不对,原因是:" & Chr(13) & 

xmlDoc.parseError.reason
                Exit Function              
        End If
  '获得根结点
        Set xmlRoot = xmlDoc.documentElement  

  '获得第二层结点
  xmlGetFloorTwo xmlRoot, xmlNodeName, xmlSectionName
        GetXml = True
       
End Function

'获得第二层结点
Function xmlGetFloorTwo(byval xmlNode, byval xmlNodeName, byval

xmlSectionName)                   
        If xmlNode.nodeName <> "Response" Then
                For Each childNodeItem In xmlNode.ChildNodes 
        If

childNodeItem.nodeName = "Response" Then
          

xmlGetFloorThree childNodeItem,xmlNodeName, xmlSectionName
        End If
                Next
        End If       
End Function

'获得第三层结点
Function xmlGetFloorThree(byval xmlNode, byval xmlNodeName, byval

xmlSectionName)                    
        If xmlNode.nodeName <> "Sections" Then
                For Each childNodeItem In xmlNode.ChildNodes 
        If

childNodeItem.nodeName = "Sections" Then
          

xmlGetFloorFour childNodeItem, xmlNodeName, xmlSectionName
        End If   

                           
                Next
        End If       
End Function

'获得第四层结点
Function xmlGetFloorFour(byval xmlNode,  byval xmlNodeName, byval

xmlSectionName)    
        If xmlNode.nodeName <> xmlSectionName Then
                For Each childNodeItem In xmlNode.ChildNodes 
        If

childNodeItem.nodeName = xmlSectionName Then
          

xmlRecursion childNodeItem, xmlNodeName                                  

           
        End If   

                                
                Next
        End If       
End Function

Function xmlRecursion(byval xmlNode,byval strNodeName)
        If xmlNode.nodeName = strNodeName And xmlNode.hasChildNodes Then
                If  xmlNode.childNodes.item(0).nodeName = "#text" Then
                        strXML =  xmlNode.nodeName & ":" &

xmlNode.childNodes.item(0).nodeValue & Chr(13)                           

                   
                End If              
        End If                       
        If xmlNode.hasChildNodes Then
                For Each childNodeItem In xmlNode.ChildNodes
                        If childNodeItem.hasChildNodes Then
                                xmlRecursion childNodeItem,strNodeName   

                           
                        End If                       
                Next
        End If       
End Function

 


TAG:

 

评分:0

我来说两句

日历

« 2024-04-29  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 6356
  • 日志数: 15
  • 建立时间: 2012-07-12
  • 更新时间: 2012-07-30

RSS订阅

Open Toolbar