Results 1 to 3 of 3

Thread: [RESOLVED] Replacing a element in xml file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    Resolved [RESOLVED] Replacing a element in xml file

    I am trying to write a script that will automate the locking down of IIS on our servers.

    What I need to do is change the MaxConnections from 1000 to 100 while keeping all the other information intact. I just need an example of how to do this then i will be able to go from there.

    Code:
    <IIsWebServer	Location ="/LM/W3SVC/1"
    		AppPoolId="DefaultAppPool"
    		DefaultDoc="Default.htm,Default.asp,index.htm,iisstart.htm"
    		MaxConnections="1000"
    		ServerBindings=":80:"
    		ServerComment="Default Web Site"
    		ServerSize="1"
    	>
    </IIsWebServer>

    There is another element call <IIsWebServer> but it doesnt contain the same information. So I dont want it to change the information in there....

    Code:
    <IIsWebServer	Location ="/LM/W3SVC/Info/Templates/Public Web Site"
    		ServerComment="Allows all users to browse static and dynamic content."
    	>
    </IIsWebServer>

    If I am confusing let me know I will try and explain better.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Replacing a element in xml file

    See if this gets you started.
    Code:
    Option Explicit
    
    Dim objDoc
    Dim objNode
    Dim objNodeList
    Dim objAttrib
    Dim strXmlFile
    
        strXmlFile = "c:\iis.xml"
    
        Set objDoc = CreateObject("Microsoft.XMLDOM")
        objDoc.async = False
        objDoc.Load strXmlFile
        
        'Get all IIsWebServer nodes that have a MaxConnections attribute
        Set objNodeList = objDoc.selectNodes("//IIsWebServer[@MaxConnections]")
        
        'loop through the returned nodes
        For Each objNode In objNodeList
            'Get a copy of the attribute you want to change
            Set objAttrib = objNode.Attributes.getNamedItem("MaxConnections")
            'Set the value of the attribute
            objAttrib.Text = "100"
        Next
        
        'Save the changes
        objDoc.save strXmlFile

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    25

    Re: Replacing a element in xml file

    thanks for a great start!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width