• <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>

            以上代碼需要測(cè)試的話請(qǐng)各位連同類和代碼COPY到本地新建一個(gè)VBS文檔運(yùn)行,運(yùn)行結(jié)果在你本機(jī)C:Dir.xml中顯示。
            請(qǐng)教各位XML高手啊。
            99久久精品国产一区二区蜜芽| 久久久久亚洲爆乳少妇无| 99久久精品免费看国产一区二区三区| 国产亚洲美女精品久久久| 久久精品综合一区二区三区| 亚洲人成电影网站久久| 亚洲精品美女久久777777| 久久91综合国产91久久精品| 久久精品中文字幕第23页| 亚洲AV无码久久精品蜜桃| 久久精品国产一区二区| 久久精品国产精品亚洲毛片| 久久久精品国产亚洲成人满18免费网站| 2021国内久久精品| 国产综合成人久久大片91| 亚洲国产精品无码久久SM| 久久久久99精品成人片三人毛片| 久久亚洲中文字幕精品有坂深雪 | 久久久久亚洲AV成人网| 亚洲精品无码久久久久去q| 天堂无码久久综合东京热| 国产精品久久久久无码av| 久久九九兔免费精品6| 久久人妻少妇嫩草AV无码蜜桃| 久久99精品国产自在现线小黄鸭 | 欧美久久天天综合香蕉伊| 99久久国产免费福利| 国产午夜久久影院| 日韩精品无码久久久久久| 久久人人爽人人爽人人av东京热| 国产精品无码久久四虎| 嫩草影院久久国产精品| 久久精品国产99国产精品澳门 | 久久精品aⅴ无码中文字字幕不卡| 亚洲国产香蕉人人爽成AV片久久 | 久久亚洲欧洲国产综合| 伊人丁香狠狠色综合久久| 国产国产成人精品久久| 999久久久免费精品国产| 久久av无码专区亚洲av桃花岛| 久久久噜噜噜久久中文福利|