Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use XPath to find the 'interesting' nodes and .removeChild to zap them:</p> <pre><code> 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=""" &amp; sDate &amp; """]" 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 </code></pre> <p>output:</p> <pre><code>====================================================================== &lt;?xml version="1.0"?&gt; &lt;addons&gt; &lt;addon id="TicTacToe" date="2012-11-05"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;addon id="Sudoku" date="2012-08-31"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;addon id="Doom" date="1953-04-13"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;addon id="Muehle" date="2012-10-18"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;/addons&gt; ----------------- found 4 nodes for /addons/addon filtering for dtX &lt;= 31.08.2012 ----------------- &lt;?xml version="1.0"?&gt; &lt;addons&gt; &lt;addon id="TicTacToe" date="2012-11-05"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;addon id="Muehle" date="2012-10-18"&gt; &lt;requires&gt; &lt;import addon="xbmc.python" version="1.0"/&gt; &lt;/requires&gt; &lt;/addon&gt; &lt;/addons&gt; ====================================================================== </code></pre> <p>The manual filtering sucks, but</p> <ol> <li>it will come handy for your not-really-usefull date format</li> <li>I can't get XPath to accept <code>&lt;=</code> resp. <code>&amp;lt;</code> in my search expression</li> </ol> <p>This much better looking code fragment:</p> <pre><code> ... Dim sXPath : sXPath = "/addons/addon[@date=""" &amp; sDate &amp; """]" 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 ... </code></pre> <p>deletes the Sudoku node, but </p> <pre><code>... Dim sXPath : sXPath = "/addons/addon[@date &amp;lt; """ &amp; sDate &amp; """]" ... </code></pre> <p>throws</p> <pre><code>msxml6.dll: Unexpected character in query string. /addons/addon[@date --&gt;&amp;&lt;--lt; "2012-08-31"] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload