473,763 Members | 6,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Simple XML help in VB.Net or C#

Hello and God Bless,

I am stumped trying to get a simple xml database replacing certain data
with other data programmaticall y. This is what my xml looks like.

*************** *************** **********
<Root_Element >
<Topic index="1">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="2">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="3">
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
</Root_Element>
*************** *************** **********

What i want to do is navigate to <Topic index="2">, and replace all
child nodes under it with new nodes.

Keep in mind that the number of nodes replacing the current ones will be
different. For instance, i wll replace the 2 <Sub_Topicsunde r <Topic
index="2"with 4 <Sub_Topicswi th different <Notesunder them.

I can read both C# and VB.Net, so it doesnt matter what language you
write in. Please help me.

Thank you all, and God Bless.

*** Sent via Developersdex http://www.developersdex.com ***
Sep 27 '06 #1
2 3148


James Fifth wrote:

<Root_Element >
<Topic index="1">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="2">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="3">
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
</Root_Element>
*************** *************** **********

What i want to do is navigate to <Topic index="2">, and replace all
child nodes under it with new nodes.
Use System.Xml.XmlD ocument e.g.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(@"file.xml") ;
// using XPath and SelectSingleNod e to find element
XmlElement topic =
xmlDocument.Sel ectSingleNode(@ "/Root_Element/Topic[@index = '2']") as
XmlElement;
if (topic != null) {
// now there are various ways to proceed
// 1: setting InnerXml e.g.
topic.InnerXml = "<Sub_Topic><No tes></Notes></Sub_Topic>";
// that parses the string on the right side into nodes and
// replaces the previous contents

// 2: creating nodes with the DOM e.g
XmlElement subtopic = xmlDocument.Cre ateElement("Sub _Topic");
XmlElement notes = xmlDocument.Cre ateElement("Not es");
notes.InnerText = "DOM example";
subtopic.Append Child(notes);

while (topic.HasChild Nodes) {
topic.RemoveChi ld(topic.LastCh ild);
}

topic.AppendChi ld(subtopic);

// save document e.g.
xmlDocument.Sav e(@"file.xml") ;
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 28 '06 #2
Hello and God Bless,

I am stumped trying to get a simple xml database replacing certain data
with other data programmaticall y. This is what my xml looks like.

*************** *************** **********
<Root_Element >
<Topic index="1">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="2">
<Sub_Topic>
<Notes></Notes>
<Notes></Notes>
<Notes></Notes>
</Sub_Topic>
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
<Topic index="3">
<Sub_Topic>
<Notes></Notes>
</Sub_Topic>
</Topic>
</Root_Element>
*************** *************** **********

What i want to do is navigate to <Topic index="2">, and replace all
child nodes under it with new nodes.

Keep in mind that the number of nodes replacing the current ones will be
different. For instance, i wll replace the 2 <Sub_Topicsunde r <Topic
index="2"with 4 <Sub_Topicswi th different <Notesunder them.

I can read both C# and VB.Net, so it doesnt matter what language you
write in. Please help me.

Thank you all, and God Bless.

*** Sent via Developersdex http://www.developersdex.com ***
Thank you for this. Though simple, I have been looking for this for a long time.

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
Nov 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1897
by: george young | last post by:
For each run of my app, I have a known set of (<100) wafer names. Names are sometimes simply integers, sometimes a short string, and sometimes a short string followed by an integer, e.g.: 5, 6, 7, 8, 9, bar, foo_6, foo_7, foo_8, foo_9, foo_10, foo_11 I need to read user input of a subset of these. The user will type a set of names separated by commas (with optional white space), but there may also be sequences indicated by a dash...
4
1917
by: C. Smith | last post by:
I am technical advisor for a new group of middle-aged people that want to create a web site for historical information about our local area. They want to scan in a lot of old photos, include information on schools, cemetaries, etc. The web server is NT4 running IIS 4.0. Pages are uploaded via FTP. I personally use Dreamweaver 3, and am learning Dreamweaver MX. I feel that Dreamweaver is too much for this group to learn. I had early...
7
2360
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
8
2324
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta) My app (an image viewer) opens with a Main form with a file explorer if you open the program with the exe, but opens with the ImageView form if you double click an image file, if you want to see the Main form once the ImageView is open the...
3
1314
by: Edwin Knoppert | last post by:
For near future specifications to place our ASP.NET software on a server not being ours i have to ask you a few rather simple questions. It's for professional use. We would not like to intervene with the installation that much, a simple copy to folder should be enough. Eventually we point the admin to change a few (minor) settings in the web.config We want to reach clients using any kind of browser.
8
2086
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a web form when one presses the button on the web form on a client pc, the sql query which is contained in the text box is sent to a vb net application on a server pc. The win application sends the query to the database, collects the results,
16
2538
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
3
3059
by: jmDesktop | last post by:
Hi, probably a simple question that I have for what I think is a simple database. I have a Vendors table and an Items table. There is only one items, but several Vendors may have that same item. I have to have a third table, correct, to connect them? I was thinking OrderDetails (or something like that) OrderDetailID
25
3131
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of course then the file doesn't get seen by the user. Is there any command that essentially executes the code and then echo's it? something that will take a string like '<body>blah<?php echo 'Hello'; ?></body>' and actually interpret the php
0
1312
by: jerger | last post by:
I posted this in ASP... does it belong here instead? I have converted my dictionary program into a simple asp program. It works great... but I now want to add speech functionality but have not had any success. I have tried several online templates that give errors... or I have added suggested code to my own... which then breaks my code! Please, if anyone is an expert in TSS ... could you make me a simple asp page template... that I can...
0
9564
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
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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
7368
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
6643
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.