XPath を使用して「興味深い」ノードを見つけ、.removeChild を使用してそれらを消去します。
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec : sFSpec = oFS.GetAbsolutePathName("..\data\01.xml")
Dim oXML : Set oXML = CreateObject("Msxml2.DOMDocument.6.0")
Dim sDate : sDate = "2012-08-31"
oXML.setProperty "SelectionLanguage", "XPath"
oXML.async = False
oXML.load sFSpec
If 0 = oXML.parseError Then
WScript.Echo oXML.xml
WScript.Echo "-----------------"
Dim sXPath : sXPath = "/addons/addon[@date=""" & sDate & """]"
Dim ndlFnd : Set ndlFnd = oXML.selectNodes(sXPath)
If 0 = ndlFnd.length Then
WScript.Echo sXPath, "not found"
Else
WScript.Echo "found", ndlFnd.length, "nodes for", sXPath
Dim ndCur
For Each ndCur In ndlFnd
ndCur.parentNode.removeChild ndCur
Next
End If
WScript.Echo "-----------------"
WScript.Echo oXML.xml
Else
WScript.Echo oXML.parseError.reason
End If
出力:
======================================================================
<?xml version="1.0"?>
<addons>
<addon id="TicTacToe" date="2012-11-05">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
<addon id="Sudoku" date="2012-08-31">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
<addon id="Doom" date="1953-04-13">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
<addon id="Muehle" date="2012-10-18">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
</addons>
-----------------
found 4 nodes for /addons/addon
filtering for dtX <= 31.08.2012
-----------------
<?xml version="1.0"?>
<addons>
<addon id="TicTacToe" date="2012-11-05">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
<addon id="Muehle" date="2012-10-18">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
</addon>
</addons>
======================================================================
手動フィルタリングは最悪ですが、
- あまり役に立たない日付形式に便利です
<=
XPath でrespを受け入れることができません。<
私の検索式で
このはるかに見栄えの良いコードフラグメント:
...
Dim sXPath : sXPath = "/addons/addon[@date=""" & sDate & """]"
Dim ndlFnd : Set ndlFnd = oXML.selectNodes(sXPath)
If 0 = ndlFnd.length Then
WScript.Echo sXPath, "not found"
Else
WScript.Echo "found", ndlFnd.length, "nodes for", sXPath
Dim ndCur
For Each ndCur In ndlFnd
ndCur.parentNode.removeChild ndCur
Next
End If
...
数独ノードを削除しますが、
...
Dim sXPath : sXPath = "/addons/addon[@date < """ & sDate & """]"
...
スロー
msxml6.dll: Unexpected character in query string.
/addons/addon[@date -->&<--lt; "2012-08-31"]