Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Change attributes AND value

I have inherited a VB Script driven by an XML file. The XML file is in a format which the developers refuse to change so I'm stuck with it. A fragment of the file looks like this:

<configuration>
<NTCredential ID="BTS_IHOST_GROUP" DisplayName="BizTalk Isolated Host Users Group" Description="Windows group for accounts with access to the Isolated BizTalk hosts">
<NTAccount ScopeType="105" UpLevelFlags="132" DownLevelFlags="2147483654">thedomain\domainuseraccountname
</NTAccount>
</NTCredential>
<more, unrelated elements, etc>
</configuration>

There are a dozen or so 'NTCredential' elements whose 'ID' attribute is unique.

I need to modify the script so that it finds a particular 'NTCredential' element, then changes the ScopeType, UpLevelFlags and DownLevelFlags attributes AND the value 'thedomain\domainuseraccountname'.

I *think* I need to use the "getElementsByTagName" method but am a complete newbie with XML. If someone can help me out with some snytax, that'd be great: as long as I can get one to work, I can handle passing in an array to a function which I will build around that syntax (I already have a WSC for updating single fields).

I'm using CreateObject("Microsoft.XMLDOM") as my XML handler.
[1412 byte] By [VBScab] at [2007-11-11 7:33:28]
# 1 Re: Change attributes AND value
A Google for my User ID reminded me about this and, on viewing, I see no-one ecver replied. Well, if you get here on a Google search looking for an answer to changing XML attributes and/or values, someone on a different forum answered this for me. See http://www.siteexperts.com/forums/viewConverse.asp?d_id=18455

If that link is dead by the time you come here, the reply was:

var ntAccountNode = xmlDom.selectSingleNode("//NTCredential[@ID='" + id + "']/NTAccount");
ntAccountNode.setAttribute("ScopeType", newScopeType);
ntAccountNode.setAttribute("UpLevelFlags", newUpLevelFlags);
ntAccountNode.setAttribute("DownLevelFlags", newDownLevelFlags);
ntAccountNode.firstChild.nodeValue = newDomainString;

Due to selectSingleNode() this is IE-specific, if you need it for Gecko based browsers too, you'll have to utilize Gecko's XPathEvaluator() object (or use a X-broser XML libray like Sarissa).

<disclaimer>This is OTTOMH and untested</disclaimer>

I posted the thread URL in case by some miracle it got expanded at any time.
VBScab at 2007-11-11 23:28:47 >