?
Solved

Edit XML Delete/ add node

Posted on 2004-09-26
3
Medium Priority
?
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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…
Starting up a Project

777 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