From: asdf on 19 Nov 2006 05:13 You seem to get along with an xml Parser, as should. Congratulation. "Highlander" <tron9901(a)msn.com> wrote in message news:1156444945.616083.70970(a)h48g2000cwc.googlegroups.com... > > Martin Honnen wrote: > > Highlander wrote: > > > > > > > If you notice I've used the variable strXMLFile for "web1.config". I'd > > > like to do the same and use a variable for "AppSettings", for "add > > > key", and for "PublishUnlicensedStaff" in the "IF > > > ConfigDoc.Load(strXMLFile) Then" section. > > > > The methods selectSingleNode and selectNodes of MSXML take a string with > > an XPath expression as the argument. > > If you want to write your own XPath expressions then you need to learn > > it, see > > <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm l/13a37981-604f-4fe9-89b7-6c435010f5b5.asp> > > > > for instance or try any XPath 1.0 tutorial you find on the web. > > > > As for using variables you simply need to use VBScript string > > concatenation to construct the XPath expressions you pass to > > selectSingleNode e.g. > > > > Sub SetKey (AppSettings, Key, NewValue) > > Set Value = AppSettings.selectSingleNode(_ > > "add[@key = '" & Key & "']/@Value") > > If Not Value Is Nothing Then > > Value.value = NewValue > > End If > > End Sub > > > > Set AppSettings = ConfigDoc.selectSingleNode(_ > > "configuration/appSettings") > > IF Not AppSettings Is Nothing Then > > SetKey AppSettings, "PublishUnlicensedStaff", "Y" > > SetKey AppSettings, "LogToFile", "N" > > SetKey AppSettings, "StateRollOut", "None" > > SetKey AppSettings, "EnableIA", "False" > > End If > > > > That approach should work without problems as long as the Key you pass > > in does not contain a single quote, in that case the XPath expression > > construction > > "add[@key = '" & Key & "']/@Value" > > would yield an XPath syntax error. Your example key values however do > > not have that problem. > > > > -- > > > > Martin Honnen --- MVP XML > > http://JavaScript.FAQTs.com/ > > After reading your last reply, while searching the web for info on > XPath, I came across the XMLStarlet command line utility at > http://xmlstar.sourceforge.net. I've created a script using this > utility and it's working fine for me. If anyone wants to see my script > I'll post it. > > Thanks for the replies Martin, it's much appreciated! > > - Dave >
|
Pages: 1 Prev: Reading Registry Keys and Values? Next: Passing uint8 and uint64 values with VBScript? |