#1 22 Mar 2013 20:51

22152Bill
Member
Registered: 22 Mar 2013
Posts: 1

use MSXML2.DOMDocument with XML

I didn't notice any information on XML files with VBScript

So I thought I would donate some simple commands in hopes that someone would add to them.



Modify XML:  (web.config for webservices)
--------------------------------------------------------------------

Set xmlDoc = CreateObject("MSXML2.DOMDocument")

xmlDoc.async = False  
xmlDoc.load("web.config")

Set objRoot = xmlDoc.documentElement

Set objConfigProtectedData = xmlDoc.createElement("configProtectedData")

Set objProvidersNode = xmlDoc.createElement("providers")
Set objProviderClearNode = xmlDoc.createElement("clear")
Set objProviderAddNode = xmlDoc.createElement("add")

objProviderAddNode.SetAttribute "name", "myEncryptionProvider"
objProviderAddNode.SetAttribute "type", "System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"
objProviderAddNode.SetAttribute "useMachineContainer", "true"
objProviderAddNode.SetAttribute "keyContainerName", "NETWORK_SERVICE"

objProvidersNode.appendChild objProviderClearNode
objProvidersNode.appendChild objProviderAddNode
objConfigProtectedData.appendChild objProvidersNode

objRoot.insertBefore objConfigProtectedData, objRoot.FirstChild
objRoot.Normalize 

xmlDoc.Save "web.config"

--------------------------------------------------------------------------------------------------------------------------


Read XML:
--------------------------------------------------------------------------------------------------------------------------

Set xmlDoc = CreateObject("MSXML2.DOMDocument")

xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.load(pthome & "web.config")

strName = cpdNode.getAttribute("name")
strType  = cpdNode.getAttribute("type")
strWMC  = cpdNode.getAttribute("useMachineContainer")
strkey    = cpdNode.getAttribute("keyContainerName")
strText   = cpdNode.text

------------------------------------------------------------------------------------------------------------------------------

Remove XML node:
------------------------------------------------------------------------------------------------------------------------------

Dim objXML, objNode

Set objXML = CreateObject("MSXML2.DOMDocument")
objXML.async = false
objXML.Load("web.config")

Set objNode = objXML.documentElement.selectSingleNode("//configuration/configProtectedData")
objNode.parentNode.removeChild(objNode)

objXML.Save ("web.config")

--------------------------------------------------------------------------------------------------------------------------------

Offline

Board footer

Powered by FluxBB