Note that there are some explanatory texts on larger screens.

plurals
  1. POClassic ASP updating child nodes in XML
    text
    copied!<p>I am trying to update a child node of an XML file IE Changing the value.</p> <p>The XML file looks like this:</p> <pre><code>&lt;user&gt; &lt;firstname&gt;Andre&lt;/firstname&gt; &lt;lastname&gt;Bruton&lt;/lastname&gt; &lt;/user&gt; </code></pre> <p>Here is my Classic asp code: </p> <pre><code>users_firstname = "Tristan" ''# New code to put in the XML file Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument") xmlObj.async = False xmlObj.setProperty "ServerHTTPRequest", True xmlObj.Load(cURL) If xmlObj.parseError.errorCode &lt;&gt; 0 Then Response.Write "Error Reading File - " &amp; xmlObj.parseError.reason &amp; "&lt;p&gt;" End If Set xmlList = xmlObj.getElementsByTagName("user") For Each xmlItem In xmlList For Each xmlItem2 In xmlItem.childNodes a = xmlItem2.nodeName if a = "firstname" then firstname = xmlItem2.text if a = "lastname" then lastname = xmlItem2.text Next Next If firstname &lt;&gt; users_firstname Then Set nodeBook = xmlObj.selectSingleNode("//firstname") nodeBook.setAttribute "firstname", users_firstname Response.Write nodeBook.getAttribute("firstname") xmlObj.save(cDir &amp; cFile) End If Set xmlObj = Nothing </code></pre> <p>The problem is that it adds a new section to the XML file instead of updating the value of firstname from Andre to Tristan. The XML looks like this:</p> <pre><code>&lt;user&gt; &lt;firstname firstname="Andre6"&gt;Andre&lt;/firstname&gt; &lt;lastname&gt;Bruton&lt;/lastname&gt; &lt;/user&gt; </code></pre> <p>What is should look like is:</p> <pre><code>&lt;user&gt; &lt;firstname&gt;Tristan&lt;/firstname&gt; &lt;lastname&gt;Bruton&lt;/lastname&gt; &lt;/user&gt; </code></pre> <p>Any idea how I can fix this?</p>
 

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