Solved

Edit XML Delete/ add node

Posted on 2004-09-26
3
609 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

12 Experts available now in Live!

Get 1:1 Help Now