473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing XML Elements programmaticall y with either 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 28 '06 #1
2 2372
XmlDocument xdoc = new XmlDocument();
string strXML = "<Root_Element> <Topic
index=\"1\"><Su b_Topic><Notes> ";
strXML += "</Notes><Notes></Notes></Sub_Topic></Topic>";
strXML += "<Topic index=\"2\"><Su b_Topic><Notes> </Notes>";
strXML += "<Notes></Notes><Notes></Notes></Sub_Topic><Sub_ Topic>";
strXML += "<Notes></Notes></Sub_Topic></Topic><Topic index=\"3\">";
strXML +=
"<Sub_Topic><No tes></Notes></Sub_Topic></Topic></Root_Element>";
xdoc.LoadXml(st rXML);
while(xdoc.HasC hildNodes)
{
for(int i = 0; i < xdoc.SelectNode s("/Root_Element/").Count; i++)
{
if(xdoc.GetElem entsByTagName(" Topic")[i].Attributes[0].Value.ToString ().Equals("2"))
{
/* Now Replace the childNodes */
}
}
}

Sep 28 '06 #2
This code is for retrieval:

XmlDocument xdoc = new XmlDocument();
string strXML = "<Root_Element> <Topic
index=\"1\"><Su b_Topic><Notes> ";
strXML += "</Notes><Notes></Notes></Sub_Topic></Topic>";
strXML += "<Topic index=\"2\"><Su b_Topic><Notes> </Notes>";
strXML += "<Notes></Notes><Notes></Notes></Sub_Topic><Sub_ Topic>";
strXML += "<Notes></Notes></Sub_Topic></Topic><Topic index=\"3\">";
strXML +=
"<Sub_Topic><No tes></Notes></Sub_Topic></Topic></Root_Element>";
xdoc.LoadXml(st rXML);
while(xdoc.HasC hildNodes)
{
for(int i = 0; i < xdoc.SelectNode s("/Root_Element/").Count; i++)
{
if(xdoc.GetElem entsByTagName(" Topic")[i].Attributes[0].Value.ToString ().Equals("2"))
{
/* Now Replace the childNodes */
}
}
}

Sep 28 '06 #3

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

Similar topics

2
2064
by: thehuby | last post by:
Isn't inserting good data and getting it out of a db a pain in the a$$? I am going to be using the Markdown text to HTML parser (http://daringfireball.net/projects/markdown/dingus) for creating HTML from user input (for a bespoke CMS) so that users can put in their own headings, lists and links etc. This is great and gets round all the issues of apostrophes etc. when inserting informaiton into a database for me.
0
992
by: manju | last post by:
Hi, I use DHTML browser as my main application window and I create elements like <p>, <table>, <img> etc dynamically using MSHTML C++ interfaces like IHTMLDocument2::createElement IHTMLDOMNode::insertBefore and these elements appear in the browser after creation and insertion into the DOM. The problem is that if I create an element, say a <p> with some text, in a
3
2680
by: Lars Grobe | last post by:
Hi, first hello, I am new to the list, and I guess my question will show that clearly. I want to use some vector operations (at the moment altivec) in existing code. It is a raytracing-based application, and for now, I would like to replace the operations on my data type vect3 (which is a float array) by operations on a vector float. The vect3 is simply a typedef to an array of floats so far.
7
2625
by: Daniel Kabs | last post by:
Hi there, for a long time I've been using tables to layout elements on a web page. Example: Say we have a 2x2 table and I'd like to put text (left aligned) and buttons (right aligned) in the top right table cell. These elements should stay on one line and the table should keep a minimum width in order to prevent wrapping. -------------------------------------------------
10
1684
by: Tom Plunket | last post by:
I've got a bunch of code that runs under a bunch of unit tests. It'd be really handy if when testing I could supply replacement functionality to verify that the right things get called without those things actually getting called, since frequently those calls take a long time to execute and do things that, well, I don't really want to do. E.g. imagine you've got a routine which takes a filespec, generates a list of files, and copies...
1
6381
by: Superfreak3 | last post by:
We have a web application that will be installed as a virtual directory. It will either default to the Default Web Site or allow the choice of the site to which the vir. dir. will be installed, if more than one sites exist on the server. Now, what I would like to do is set the ASP.NET version to 2.0 if it defaults to an earlier version (more than one instance of the Framework is installed). I would like to be able to do this...
2
3267
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server or Access database as following : It will connect first to the Master database (SQL or Access, connection String of this database should be read from the C:\WINDOWS
1
6026
by: MarkShoe | last post by:
Hi, I have an aspx with a control on it, lets call it myControl, and I have an external javascript file. In the external javascript file, I have var myControlId = '<%=myControl.ClientID%>'; which would work fine if the javascript was in the .aspx file, but when
29
19292
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
0
10457
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
10231
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
10013
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
9054
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
7550
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
6792
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();...
1
4119
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
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
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.