Solved

Edit XML Delete/ add node

Posted on 2004-09-26
3
611 Views
Last Modified: 2013-11-13
/*classic ASP*/ I have two XML files here file1 and file2 , file1 is what I need to edit , I need to delete the node from file1 with the id-"idNodeToDelete" and repleace it with the node from file2 id="nodetoAdd" , does anyone know of a way to do this in classic ASP.
Appreciate the help


/****** File1 ********/
<?xml version="1.0" encoding="UTF-8"?>
<REQUEST>
      <GET_IMAGE>
            <PROPERTIES>
                  <DRAW map="true"/>
                  <LAYERLIST order="true" nodefault="false">
                        <LAYERDEF visible="true" id="idNodeToDelete" type="polygon">
                              <VALUEMAPRENDERER lookupfield="test">
                                    <EXACT value="P;Q;R;S;" label="">
                                          <SIMPLEPOLYGONSYMBOL fillcolor="254,236,134" filltype="solid"/>
                                    </EXACT>
                                    <EXACT value="A;B;C;D;E;" label="">
                                          <SIMPLEPOLYGONSYMBOL fillcolor="254,221,40" filltype="solid"/>
                                    </EXACT>
                              </VALUEMAPRENDERER>
                        </LAYERDEF>
                  </LAYERLIST>
            </PROPERTIES>
      </GET_IMAGE>
</REQUEST>


 /***** file 2  **** /
<?xml version="1.0" encoding="UTF-8"?>
<LAYERDEF id="nodetoAdd">
      <VALUEMAPRENDERER lookupfield="NAME">
            <EXACT label="myLabel1" method="IsExact" value="P;Q;R;S;">
                  <SIMPLEPOLYGONSYMBOL fillcolor="254,249,224" boundarytransparency="1.0"/>
            </EXACT>
            <EXACT label="myLabel2" method="IsExact" value="A;B;C;D;E;">
                  <SIMPLEPOLYGONSYMBOL fillcolor="254,236,134" boundarytransparency="1.0"/>
            </EXACT>
      </VALUEMAPRENDERER>
</LAYERDEF>


0
Comment
Question by:vbothello
  • 2
3 Comments
 

Author Comment

by:vbothello
ID: 12156021
I know I am wrong as I get errors , I am pretty new to XML so and cant seem to  seem to figure out the way to do it.

set node1 = Server.CreateObject("MSXML2.DOMDocument.4.0") '
'** DELETE THE NODE
set node1 = file1.SelectSingleNode("//*[@id[value()='idNodeToDelete']]")
node1.ParentNode.RemoveChild(node)

'** ADD THE NEW NODE
set node2 = file2.getElementsByTagName("LAYERDEF")
Set currentElement = file1.selectSingleNode("//LAYERDEF").appendChild(node2)   ' WONT ACCEPT THIS ?
0
 

Author Comment

by:vbothello
ID: 12156050
I know I am wrong as I get errors

set node1 = Server.CreateObject("MSXML2.DOMDocument.4.0") '
'** DELETE THE NODE
set node1 = file1.SelectSingleNode("//*[@id[value()='idNodeToDelete']]")
node1.ParentNode.RemoveChild(node)

'** ADD THE NEW NODE
set node2 = file2.getElementsByTagName("LAYERDEF")
Set currentElement = file1.selectSingleNode("//LAYERDEF").appendChild(node2)   ' WONT ACCEPT THIS ?
0
 
LVL 4

Accepted Solution

by:
avi247 earned 500 total points
ID: 12162418
Dim node1 As Object
Dim node2 As Object
Dim node3 As Object
Dim nodepar As Object
Dim file1 As Object
Dim file2 As Object

Set file1 = CreateObject("MSXML2.DOMDocument")
Set file2 = CreateObject("MSXML2.DOMDocument")

file1.Load ("C:\File1.xml")
file2.Load ("C:\File2.xml")
 
Set node1 = file1.selectSingleNode("//*[@id[value()='idNodeToDelete']]") ' find the child to be removed
Set nodepar = node1.parentNode ' go to parent
Set node2 = file2.selectSingleNode("LAYERDEF") ' get required node from second file
Set node3 = nodepar.appendChild(node2)  ' add it
Set nodepar = node3.parentNode ' go back to it parent
Set nodepar = nodepar.removeChild(node1) 'remove the child
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question