473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing Nodes with ASP

7 New Member
This has posted in the ASP sub-forum, to no avail I re-post here.

Hello there, I have an XML file of structure that looks like this:


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?> 
  2.  <documents> 
  3.    <header id="1">
  4.       <title></title> 
  5.       <prodGroup></prodGroup>
  6.       <version> 
  7.          <major></major> 
  8.          <minor></minor> 
  9.       </version> 
  10.    </header> 
  11.    <header id="2"> 
  12.      <title></title> 
  13.      <prod</prodGroup> 
  14.      <version> 
  15.         <major></major> 
  16.         <minor></minor> 
  17.      </version> 
  18.   </header> 
  19. </documents>
  20.  


The program I am currently writting will need to replace an entire header node. This is what the replace method looks like:


Expand|Select|Wrap|Line Numbers
  1. Private Function SaveHeader() As Boolean
  2.  
  3.             'get the entire  xml file to be saved to
  4.             Dim headerDocument As XmlDocument = FileManager.GetQAHeaderFile(m_header.ProductGroup)  
  5.         'read the appropriate Node and load it into it's class
  6.             Dim oldHeader As QAHeader = QAHeader.Find(m_header.ProductGroup, m_header.Id)
  7.  
  8.             'If an old header exists, overwrite, else add new header
  9.             If oldHeader Is Nothing Then
  10.                 headerDocument.DocumentElement.AppendChild(m_heade  r.CreateXMLNode(headerDocument))
  11.             Else
  12.                 'make a node out of the instance read above
  13.                 Dim oldNode As XmlNode = oldHeader.CreateXMLNode(headerDocument)
  14.         'make a node out of the information given via form
  15.                 Dim newNode As XmlNode = m_header.CreateXMLNode(headerDocument)
  16.                 'THIS LINE HERE!
  17.                 headerDocument.ReplaceChild(newNode, oldNode)
  18.             End If
  19.  
  20.             'Now the save the xml file to disk
  21.             headerDocument.Save(FileManager.GetQAHeaderLocatio  n(m_header.ProductGroup))
  22.             Return True
  23.         End Function


The problem here is that I keep getting a runtime error claiming that "The node to be removed is not a child of this node." I tried to make oldNode contain everything in <documents></documents> but then the ReplaceChild methods deletes all other <header id=""></header> nodes and I'm left with only the contents of newNode.

Allow me to give you an example. I have


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <documents>
  3.   <header id="1">
  4.     <title>Whut</title>
  5.     <prodGroup>Audio &amp; Video</prodGroup>
  6.     <version>
  7.       <major>1</major>
  8.       <minor>3</minor>
  9.     </version>
  10.   </header>
  11.   <header id="2">
  12.     <title>teh</title>
  13.     <prodGroup>Audio &amp; Video</prodGroup>
  14.     <version>
  15.       <major>5</major>
  16.       <minor>0</minor>
  17.     </version>
  18.   </header>
  19. <header id="3">
  20.   <title>feck!@#</title>
  21.   <prodGroup>Audio &amp; Video</prodGroup>
  22.   <version>
  23.     <major>7</major>
  24.     <minor>2</minor>
  25.   </version>
  26. </header>
  27. </documents>
  28.  


The user wishes to change <title>feck!@ #</title> to something a little less vulgar. Iterating thru the method presented above we have the outerXML of newNode & oldNode to read:

oldNode:
"<header id="3"><title>f eck!@#</title><prodGrou p>Audio &amp; Video</prodGroup><vers ion><major>7</major><minor>2</minor></version></header>"

newNode:
"<header id="3"><title>t ruck</title><prodGrou p>Audio &amp; Video</prodGroup><vers ion><major>1</major><minor>0</minor></version></header>"

At this time I'd like to say that regardless of what element has been changed I would like the entire contents of the appropriate <header> node to be rewritten. Is this possible and how?

Any help/suggestions are greatly appreciated. Thank you for your time and patience.
Oct 23 '06 #1
0 1643

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2983
by: Charles Crume | last post by:
Hello all; I have a web page that displays a blank gif for about 2 seconds, then displays an animated gif image, then, after the animation plays, I want to display a link so the user can click on it and go to another page. I am fairly new to javascript and came up with the following code: ----------------------- <p align="center"><img src="images/nil.gif" align="middle" width="375" height="300" name="blank_image"></p>
0
925
by: Nick Wong | last post by:
I am using a XmlValidatingReader to validate an xml against a xsd schema. What I would like to achieve is to "mark" each invalid node element with an attribute. The resultant xml is then passed to the next stage of the processing pipeline. Therefore, an xml fragment such as: <bk:book publisher="WROX"> <bk:title>XSLT Programmer's Reference</bk:title>
12
2604
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
2
7090
by: André | last post by:
I've started using elementtree and don't understand how to use it to manipulate and replace nodes. I know how to do this using a simple, but inefficient parser I wrote, but I'd rather learn to use a better tool - especially as it is to be added to the standard library. I'll use a simple, but representative example. Suppose I have the following text, where I inserted blank lines to isolate the part I want to manipulate....
1
1254
by: dotnetnoob | last post by:
i need to copy several xml files and use it as xml element and insert them into a xml file. i use DOM support in .Net and from the pervious help i was able to copy and insert them into the xml file that i want but i need to change some xml node value before i insert. what is the best way to do this?
4
7473
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
2
2370
by: James Fifth | last post by:
Hello and God Bless, I am stumped trying to get a simple xml database replacing certain data with other data programmatically. This is what my xml looks like. **************************************** <Root_Element> <Topic index="1"> <Sub_Topic> <Notes></Notes>
0
1457
by: theFLY | last post by:
Hello there, I have an XML file of structure that looks like this: <?xml version="1.0"?> <documents> <header id="1"> <title></title> <prodGroup></prodGroup> <version> <major></major> <minor></minor>
1
2652
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming from C/C++ background, it looks like a functional language I'm not familiar with. Here's the link to where I got the code (thanks goes to the author), but I don't have a strong enough background in xsl to tell what is going on. xslfile.xsl ...
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.