473,785 Members | 2,234 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 2371
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
2063
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
991
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
2679
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
1683
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
6025
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
19290
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
9645
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...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7502
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
6741
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
5383
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...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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.