Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 14th, 2006, 10:28 PM
Highlander
Guest
 
Posts: n/a
Default Using XML DOM to update machine.config

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\CONFI G\"
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

  #2  
Old December 14th, 2006, 10:28 PM
mr_unreliable
Guest
 
Posts: n/a
Default Re: Using XML DOM to update machine.config

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:
Quote:
Any help would be greatly appreciated.
Thanks!
>
- Dave
>
  #3  
Old December 14th, 2006, 10:28 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: Using XML DOM to update machine.config

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.
  #4  
Old December 15th, 2006, 07:35 PM
Highlander
Guest
 
Posts: n/a
Default Re: Using XML DOM to update machine.config


mr_unreliable wrote:
Quote:
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:
Quote:
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

  #5  
Old December 19th, 2006, 05:55 PM
mr_unreliable
Guest
 
Posts: n/a
Default Re: Using XML DOM to update machine.config

--- <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:
Quote:
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
>
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles