Solved

Edit XML Delete/ add node

Posted on 2004-09-26
3
608 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now