473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create 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>feck!@#</title><prodGroup>Audio &amp; Video</prodGroup><version><major>7</major><minor>2</minor></version></header>"

newNode:
"<header id="3"><title>truck</title><prodGroup>Audio &amp; Video</prodGroup><version><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 1620

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

Similar topics

4
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...
0
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...
12
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
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...
1
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...
4
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...
2
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. ...
0
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> ...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
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...
0
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...
0
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 ...

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.