Solved

Edit XML Delete/ add node

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
python sqlite question 11 46
Path to Python 9 118
"Black Box" Testing of Control System Software 2 49
i am cortana ask me anything 5 51
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

813 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

18 Experts available now in Live!

Get 1:1 Help Now