Using XML DOM to update machine.config

Discussion in 'XML' started by Highlander, Dec 13, 2006.

  1. Highlander

    Highlander Guest

    Hello all.
    The following lines are an excerpt from a machine.config file:

    <configuration>
    <system.net>
    <connectionManagement>
    <add address="*" maxconnection="10"/>
    </connectionManagement>
    </system.net>

    <system.web>
    <processModel
    enable="true"
    timeout="Infinite"
    idleTimeout="Infinite"
    shutdownTimeout="0:00:05"
    requestLimit="Infinite"
    requestQueueLimit="5000"
    restartQueueLimit="10"
    memoryLimit="60"
    webGarden="false"
    cpuMask="0xffffffff"
    userName="machine"
    password="AutoGenerate"
    logLevel="Errors"
    clientConnectedCheck="0:00:05"
    comAuthenticationLevel="Connect"
    comImpersonationLevel="Impersonate"
    responseDeadlockInterval="00:03:00"
    maxWorkerThreads="100"
    maxIoThreads="100"
    minWorkerThreads="50"
    />
    </system.web>
    </configuration>

    I'm using the following VBScript to edit the machine.config file and
    change the "maxconnection" value from 10 to 48:

    Dim strServer, XMLFilePath, XMLFileName, XMLFile, XMLFileBak
    strServer = "000-WEB15-CRS"
    XMLFilePath = "\\" & strServer & _
    "\C$\Winnt\Microsoft.NET\Framework\v1.1.4322\CONFIG\"
    XMLFileName = "machine.config"
    XMLFile = XMLFilePath & XMLFileName
    XMLFileBak = XMLFileName & "_Backup_" & ".txt"

    Set xmlDoc = CreateObject("Msxml.DOMDocument")
    xmlDoc.async = False
    xmlDoc.PreserveWhitespace = True
    xmlDoc.load XMLFile

    '~~~ Create backup of original XML file
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    CreateObject("Scripting.FilesystemObject") _
    .GetFile(XMLFile).Name = XMLFileBak

    Dim strNode, strKeyName, strNewValue
    strNode = "/*/*/*/*[@address=" & Chr(34) & "*" & Chr(34) & "]"
    strKeyName = "maxconnection"
    strNewValue = "48"

    Set objNode = xmlDoc.selectSingleNode (strNode)
    objNode.setAttribute strKeyName, strNewValue
    xmlDoc.Save XMLFile

    Set xmlDoc = nothing
    Set objFSO = nothing
    Set objNode = nothing

    The script works fine, except for one thing. The whitespace appears to
    be preserved throughout the machine.config file - except for the
    "<processModel" section. This section gets changed - the entire section
    ends up on one horizontal line:

    <processModel enable="true" timeout="Infinite"
    idleTimeout="Infinite" shutdownTimeout="0:00:05"
    requestLimit="Infinite" requestQueueLimit="5000" restartQueueLimit="10"
    memoryLimit="60" webGarden="false" cpuMask="0xffffffff"
    userName="machine" password="AutoGenerate" logLevel="Errors"
    clientConnectedCheck="0:00:05" comAuthenticationLevel="Connect"
    comImpersonationLevel="Impersonate" responseDeadlockInterval="00:03:00"
    maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>

    Any idea what's causing this? Any help would be greatly appreciated.
    Thanks!

    - Dave
    Highlander, Dec 13, 2006
    #1
    1. Advertising

  2. Highlander, if you want your generated xml to be tidy,
    then you are going to have to tidy it up yourself.

    There are a number of "tidy-up-xml" mini-apps out there.
    I wrote one myself in about an hour.

    cheers, jw
    ____________________________________________________________

    You got questions? WE GOT ANSWERS!!! ..(but,
    no guarantee the answers will be applicable to the questions)


    Highlander wrote:
    > Any help would be greatly appreciated.
    > Thanks!
    >
    > - Dave
    >
    mr_unreliable, Dec 14, 2006
    #2
    1. Advertising

  3. Can't post to the Microsoft newsgroups, so this answer may not help
    Highlander unless s/he is reading c.t.x...

    Whitespace between XML attributes is not meaningful, and most XML tools
    don't retain it or attempt to prettify it. You could try finding a
    serializer which does so and plug that into your processing, or you
    could write your own (warning: doing this right is nontrivial; you
    should probably look at adapting one rather than trying to do it from
    scratch), or you could postprocess the document to prettify the
    attribute indentation -- or you could simply not worry about it, since
    the change is harmless unless some other tool is badly broken.
    Joseph Kesselman, Dec 14, 2006
    #3
  4. Highlander

    Highlander Guest

    mr_unreliable wrote:
    > Highlander, if you want your generated xml to be tidy,
    > then you are going to have to tidy it up yourself.
    >
    > There are a number of "tidy-up-xml" mini-apps out there.
    > I wrote one myself in about an hour.
    >
    > cheers, jw
    > ____________________________________________________________
    >
    > You got questions? WE GOT ANSWERS!!! ..(but,
    > no guarantee the answers will be applicable to the questions)
    >
    >
    > Highlander wrote:
    > > Any help would be greatly appreciated.
    > > Thanks!
    > >
    > > - Dave
    > >


    jw - Can you post the code for the "tidy-up-xml" mini-app that you
    wrote? Or point me in the direction of where I can find the other
    mini-apps that are out there? Thanks!

    - Dave
    Highlander, Dec 15, 2006
    #4
  5. --- <snipper> ---
    ' retrieve the (untidy) xml from the dom...
    Dim sXML ' as string
    sXML = xmlDoc.xml
    ' MsgBox(sXML)

    ' ----------------------------------------------
    ' tidy up the result...
    ' ----------------------------------------------
    Dim sTidyXML ' as string
    ' (first step) tidy the result...
    sTidyXML = Replace(sXML, ">", ">" & vbCrLf)
    ' (second step)
    sTidyXML = Replace(sTidyXML, "<", " <")
    ' MsgBox(sTidyXML)
    ' (third step) remove indent from rootnode tags...
    sTidyXML = Replace(sTidyXML, " <?", "<?")
    sTidyXML = Replace(sTidyXML, vbCrLf & vbCrLf, vbCrLf)
    sTidyXML = Replace(sTidyXML, " <" & sRootNodeName, "<" &
    sRootNodeName)
    sTidyXML = Replace(sTidyXML, " </" & sRootNodeName, "</" &
    sRootNodeName)
    MsgBox(sTidyXML)

    ' sXMLTidySpec = GetLocalDirectory() & sXMLTidyFile ' for debugging
    sXMLTidySpec = fso.GetSpecialFolder(tempFolder) & "\" & sXMLTidyFile
    ' construct the output file...
    dbPrint sMe & "save xml tidy file: " & sXMLTidySpec

    ' write out the tidy file...
    Dim oFile, oTextStream ' as object(s)
    fso.CreateTextFile sXMLTidySpec, allowOverwrite ' creates the file
    (no return)...
    Set oXMLOutFile = fso.GetFile(sXMLTidySpec) ' "objectify" the file...

    Set oTextStream = oXMLOutFile.OpenAsTextStream(ForWriting) ' ,
    TristateUseDefault)
    oTextStream.Write sTidyXML
    oTextStream.Close

    --- <end snippet> ---

    Crude but effective, jw

    Highlander wrote:
    > jw - Can you post the code for the "tidy-up-xml" mini-app that you
    > wrote? Or point me in the direction of where I can find the other
    > mini-apps that are out there? Thanks!
    >
    > - Dave
    >
    mr_unreliable, Dec 19, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFuaWVs?=

    Machine.config & web.config

    =?Utf-8?B?RGFuaWVs?=, Jan 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    13,254
    Hermit Dave
    Jan 18, 2004
  2. Ivan
    Replies:
    1
    Views:
    3,032
    Natty Gur
    May 21, 2004
  3. Carlos

    machine.config vs web.config

    Carlos, Apr 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    9,161
    Juan T. Llibre
    Apr 18, 2005
  4. Replies:
    2
    Views:
    735
    Bruce Barker
    Dec 2, 2005
  5. CSharpner
    Replies:
    0
    Views:
    428
    CSharpner
    Apr 19, 2004
Loading...

Share This Page