• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運(yùn)轉(zhuǎn),開心的工作
            簡單、開放、平等的公司文化;尊重個(gè)性、自由與個(gè)人價(jià)值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            網(wǎng)上找了個(gè)VBS操作XML的類,代碼如下:
            Class clsXML
            'strFile must be full path to document, ie C:XMLXMLFile.XML
            'objDoc is the XML Object
            Private strFile, objDoc

            '*********************************************************************
            ' Initialization/Termination
            '*********************************************************************

            'Initialize Class Members
            Private Sub Class_Initialize()
            strFile = ""
            End Sub

            'Terminate and unload all created objects
            Private Sub Class_Terminate()
            Set objDoc = Nothing
            End Sub

            '*********************************************************************
            ' Properties
            '*********************************************************************

            'Set XML File and objDoc
            Public Property Let File(str)
            Set objDoc = CreateObject("Microsoft.XMLDOM")
            objDoc.async = False
            strFile = str
            objDoc.Load strFile
            End Property

            'Get XML File
            Public Property Get File()
            File = strFile
            End Property

            '*********************************************************************
            ' Functions
            '*********************************************************************

            'Create Blank XML File, set current obj File to newly created file
            Public Function createFile(strPath, strRoot)
            Dim objFSO, objTextFile
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objTextFile = objFSO.CreateTextFile(strPath, True)
            objTextFile.WriteLine("<?xml version=""1.0"" encoding=""gb2312""?>")
            objTextFile.WriteLine("<" & strRoot & "/>")
            objTextFile.Close
            Me.File = strPath
            Set objTextFile = Nothing
            Set objFSO = Nothing
            End Function

            'Get XML Field(s) based on XPath input from root node
            Public Function getField(strXPath)
            Dim objNodeList, arrResponse(), i
            Set objNodeList = objDoc.documentElement.selectNodes(strXPath)
            ReDim arrResponse(objNodeList.length)
            For i = 0 To objNodeList.length - 1
            arrResponse(i) = objNodeList.Dir(i).Text
            Next
            getField = arrResponse
            End Function

            'Update existing node(s) based on XPath specs
            Public Function updateField(strXPath, strData)
            Dim objField
            For Each objField In objDoc.documentElement.selectNodes(strXPath)
            objField.DirName= strData
            Next
            objDoc.Save strFile
            Set objField = Nothing
            updateField = True
            End Function

            'Create node directly under root
            Public Function createRootChild(strNode)
            Dim objChild
            Set objChild = objDoc.createNode(1, strNode, "")
            objDoc.documentElement.appendChild(objChild)
            objDoc.Save strFile
            Set objChild = Nothing
            End Function

            'Create a child node under root node with attributes
            Public Function createRootNodeWAttr(strNode, attr, val)
            Dim objChild, objAttr
            Set objChild = objDoc.createNode(1, strNode, "")
            If IsArray(attr) And IsArray(val) Then
            If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then
            Exit Function
            Else
            Dim i
            For i = LBound(attr) To UBound(attr)
            Set objAttr = objDoc.createAttribute(attr(i))
            objChild.setAttribute attr(i), val(i)
            Next
            End If
            Else
            Set objAttr = objDoc.createAttribute(attr)
            objChild.setAttribute attr, val
            End If
            objDoc.documentElement.appendChild(objChild)
            objDoc.Save strFile
            Set objChild = Nothing
            End Function

            'Create a child node under the specified XPath Node
            Public Function createChildNode(strXPath, strNode)
            Dim objParent, objChild
            For Each objParent In objDoc.documentElement.selectNodes(strXPath)
            Set objChild = objDoc.createNode(1, strNode, "")
            objParent.appendChild(objChild)
            Next
            objDoc.Save strFile
            Set objParent = Nothing
            Set objChild = Nothing
            End Function

            'Create a child node(s) under the specified XPath Node with attributes
            Public Function createChildNodeWAttr(strXPath, strNode, attr, val)
            Dim objParent, objChild, objAttr
            For Each objParent In objDoc.documentElement.selectNodes(strXPath)
            Set objChild = objDoc.createNode(1, strNode, "")
            If IsArray(attr) And IsArray(val) Then
            If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then
            Exit Function
            Else
            Dim i
            For i = LBound(attr) To UBound(attr)
            Set objAttr = objDoc.createAttribute(attr(i))
            objChild.SetAttribute attr(i), val(i)
            Next
            End If
            Else
            Set objAttr = objDoc.createAttribute(attr)
            objChild.setAttribute attr, val
            End If
            objParent.appendChild(objChild)
            Next
            objDoc.Save strFile
            Set objParent = Nothing
            Set objChild = Nothing
            End Function

            'Delete the node specified by the XPath
            Public Function deleteNode(strXPath)
            Dim objOld
            For Each objOld In objDoc.documentElement.selectNodes(strXPath)
            objDoc.documentElement.removeChild objOld
            Next
            objDoc.Save strFile
            Set objOld = Nothing
            End Function
            End Class


            然后,我參照上面的類寫了個(gè)目錄島,代碼如下:

            Dim objXML, strPath, str

            Set objXML = New clsXML

            strPath = "c:Dir.xml"

            objXML.createFile strPath, "Dir_Island"
            '<!-- 創(chuàng)建3個(gè)根節(jié)點(diǎn) -->
            objXML.createRootNodeWAttr "Dir", Array("DirID","DirName", "DirOwner", "DirDescption","CreateTime"), _
            Array(1,"Dir1", "Lili", "a",now)
            objXML.createRootNodeWAttr "Dir", Array("DirID","DirName", "DirOwner", "DirDescption","CreateTime"), _
            Array(2,"Dir2", "Jony", "b",now)
            objXML.createRootNodeWAttr "Dir", Array("DirID","DirName", "DirOwner", "DirDescption","CreateTime"), _
            Array(3,"Dir3", "Self", "c",now)
            '<!-- 在第一個(gè)根節(jié)點(diǎn)中創(chuàng)建1個(gè)子節(jié)點(diǎn)可以成功 -->
            objXML.createChildNodeWAttr "Dir[@DirName='Dir1']", "Dir", _
            Array("DirID","DirName", "DirOwner", "DirDescption","CreateTime"), _
            Array(4,"Sub_Dir1", "Jony1", "bb",now)
            '<!-- 在剛才創(chuàng)建的子節(jié)點(diǎn)中再創(chuàng)建1個(gè)子節(jié)點(diǎn)怎么就不行? -->
            objXML.createChildNodeWAttr "Dir[@DirName='Sub_Dir1']", "Dir", _
            Array("DirID","DirName", "DirOwner", "DirDescption","CreateTime"), _
            Array(5,"Sub_Sub_Dir1", "Jony2", "bbb",now)

            Set objXML = Nothing

            '程序運(yùn)行完后生成的XML文件如下:
            ' <?xml version="1.0" encoding="gb2312" ?>
            '- <Dir_Island>
            ' - <Dir DirID="1" DirName="Dir1" DirOwner="Lili" DirDescption="a" CreateTime="3/30/2004 9:03:11 AM">
            ' <Dir DirID="4" DirName="Sub_Dir1" DirOwner="Jony1" DirDescption="bb" CreateTime="3/30/2004 9:03:11 AM" />
            ' </Dir>
            ' <Dir DirID="2" DirName="Dir2" DirOwner="Jony" DirDescption="b" CreateTime="3/30/2004 9:03:11 AM" />
            ' <Dir DirID="3" DirName="Dir3" DirOwner="Self" DirDescption="c" CreateTime="3/30/2004 9:03:11 AM" />
            ' </Dir_Island>

            '為什么不是這樣的呢?

            ' <?xml version="1.0" encoding="gb2312" ?>
            '- <Dir_Island>
            ' - <Dir DirID="1" DirName="Dir1" DirOwner="Lili" DirDescption="a" CreateTime="3/30/2004 9:03:11 AM">
            ' <Dir DirID="4" DirName="Sub_Dir1" DirOwner="Jony1" DirDescption="bb" CreateTime="3/30/2004 9:03:11 AM">
            ' <Dir DirID="5" DirName="Sub_Sub_Dir1" DirOwner="Jony2" DirDescption="bbb" CreateTime="3/30/2004 9:03:11 AM" />
            ' </Dir>
            ' </Dir>
            ' <Dir DirID="2" DirName="Dir2" DirOwner="Jony" DirDescption="b" CreateTime="3/30/2004 9:03:11 AM" />
            ' <Dir DirID="3" DirName="Dir3" DirOwner="Self" DirDescption="c" CreateTime="3/30/2004 9:03:11 AM" />
            ' </Dir_Island>

            以上代碼需要測試的話請各位連同類和代碼COPY到本地新建一個(gè)VBS文檔運(yùn)行,運(yùn)行結(jié)果在你本機(jī)C:Dir.xml中顯示。
            請教各位XML高手啊。
            精品久久久久久久久午夜福利| 2021国产精品午夜久久| 婷婷国产天堂久久综合五月| 7国产欧美日韩综合天堂中文久久久久| 婷婷伊人久久大香线蕉AV | 国产精品成人久久久久久久| 久久亚洲精品中文字幕| 99精品国产99久久久久久97| 久久人人爽人人爽人人av东京热| 欧美精品丝袜久久久中文字幕 | www性久久久com| 精品国产乱码久久久久久郑州公司| 亚洲综合精品香蕉久久网| 久久天天躁夜夜躁狠狠躁2022| 久久久这里有精品| 一本色道久久99一综合| 久久亚洲中文字幕精品有坂深雪| 久久久久人妻精品一区二区三区| 久久国产精品99精品国产| 99久久精品影院老鸭窝| 伊人丁香狠狠色综合久久| 国产精品九九久久免费视频| 久久国产影院| 狠狠色狠狠色综合久久| 欧美大香线蕉线伊人久久| 久久99久久99小草精品免视看| 久久精品成人免费网站| 久久久久这里只有精品| 久久精品久久久久观看99水蜜桃| 久久夜色精品国产噜噜麻豆| 人人狠狠综合久久亚洲婷婷| 久久久久九国产精品| 久久久久亚洲精品日久生情| 成人久久综合网| 亚洲а∨天堂久久精品9966| 久久久无码一区二区三区 | 久久久久一本毛久久久| 亚洲午夜久久久影院伊人| 999久久久免费国产精品播放| 亚洲а∨天堂久久精品| 久久国产精品99精品国产987|