This script:
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec : sFSpec = oFS.GetAbsolutePathName("..estdataxmlso11781815.xml")
Dim oXML : Set oXML = CreateObject("Msxml2.DOMDocument")
oXML.setProperty "SelectionLanguage", "XPath"
oXML.async = False
oXML.load sFSpec
If 0 = oXML.parseError Then
WScript.Echo oXML.xml
WScript.Echo "-----------------"
Dim sXPath : sXPath = "/project/scenes/scene/rootgroup/nodelist/module[@name=""Write_1080P""]/option/disabled"
Dim ndFnd : Set ndFnd = oXML.selectSingleNode(sXPath)
If ndFnd Is Nothing Then
WScript.Echo sXPath, "not found"
Else
WScript.Echo ndFnd.nodeName, ndFnd.getAttribute("val")
WScript.Echo "-----------------"
ndFnd.setAttribute "val", "disabled"
WScript.Echo oXML.xml
End If
Else
WScript.Echo oXML.parseError.reason
End If
output:
<project>
<scenes>
<scene>
<rootgroup>
<nodelist>
<module type="WRITE" name="Write_1080P">
<option>
<disabled val="true"/>
</option>
</module>
</nodelist>
</rootgroup>
</scene>
</scenes>
</project>
-----------------
disabled true
-----------------
<project>
<scenes>
<scene>
<rootgroup>
<nodelist>
<module type="WRITE" name="Write_1080P">
<option>
<disabled val="disabled"/>
</option>
</module>
</nodelist>
</rootgroup>
</scene>
</scenes>
</project>
shows how to use .setProperty "SelectionLanguage", "XPath"
to make sure that XPath queries are processed, how to query for an attribute value (..t/module[@name=""Write_1080P""]/opt..
), and how to read (.getAttribute("val")
) and write (.setAttribute "val", "disabled"
) an attribute.
P.S.
Look here to see how you can look for/change text (with essentially the same code).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…