473,672 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Processing and c#

Hi all, just looking for a little guidance with xml procerssing.

Imagine the scenario, I have a XmlDocument object populated with XML. I need
to find and replaces some of the text in one of the nodes, i.e. the basic
XML below, I want to substitute _replace_with_v alue_ with some data,

<root>
....
<tag>_replace_w ith_value_</tag>
....
</root>

What is the process for doing this. I can find the node using
SelectSingleNod e, however this extracts it into a new NodeElement, what do I
need todo to perform a simple search and replace on my main document object?

Thanks,

Kind regards
Taz
Dec 2 '05 #1
6 1503
SelectSingleNod e does not extract the node into a new XmlNode. It
returns the node from the document that matched the selection criteria.

So, if you say:

XmlNode tagNode = doc.SelectSingl eNode("root/tag");
tagNode.InnerTe xt = "changed";

then the contents of the tag within the XML document doc will change to
"changed". tagNode is a reference into the XmlDocument, not a copy.

Dec 2 '05 #2
Many thanks Bruce, problem solved. However a further question to increase my
understanding, why does a namespace object have to be given to the
SelectSingleNod e member before executing?

i.e.

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nsmgr.AddNamesp ace("xsi", http://www.w3.org/2001/XMLSchema-instance);

what does this achieve?

Thanks again,
Taz
Dec 2 '05 #3
Namespaces in XML server pretty much the same purpose as they do in .NET
Framework. They serve to disambiguate between element tag names that may be
the same but belong to different groups. That's the short answer, if you
really wnat to get farther into XML the Quickstarts has some samples and MSDN
Online has extensive documentation.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tarun Mistry" wrote:
Many thanks Bruce, problem solved. However a further question to increase my
understanding, why does a namespace object have to be given to the
SelectSingleNod e member before executing?

i.e.

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nsmgr.AddNamesp ace("xsi", http://www.w3.org/2001/XMLSchema-instance);

what does this achieve?

Thanks again,
Taz

Dec 2 '05 #4
Hi,
this might be useful in some scenarios like when you have a new child with
which you want to replace with your old child node. as well, it will help
you to replace a old child in a document with new child from some other
document,

XmlNode node = doc.SelectSingl eNode("//root/firstchild");

XmlNode node1 = doc.SelectSingl eNode("//root/secondchild");

node.ParentNode .ReplaceChild(n ode1,node);

If you have a new child element - node1 is from other document then

node.ParentNode .ReplaceChild(d oc..ImportNode( node1,true), ,node);

HTH,

"Bruce Wood" <br*******@cana da.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
SelectSingleNod e does not extract the node into a new XmlNode. It
returns the node from the document that matched the selection criteria.

So, if you say:

XmlNode tagNode = doc.SelectSingl eNode("root/tag");
tagNode.InnerTe xt = "changed";

then the contents of the tag within the XML document doc will change to
"changed". tagNode is a reference into the XmlDocument, not a copy.

Dec 3 '05 #5
And it is only required when you are using some elements with some prefix
like myns:mynode then myns must be tied with some namespace so you have to
use namespace in that scenario only else no namespace is required and its
only purpose is to distinguish the elements with the same name [if it is
there] from different namespaces like what Namespace in .Net serves the
purpose....
Agree with Peter,

HTH,
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:2F******** *************** ***********@mic rosoft.com...
Namespaces in XML server pretty much the same purpose as they do in .NET
Framework. They serve to disambiguate between element tag names that may be the same but belong to different groups. That's the short answer, if you
really wnat to get farther into XML the Quickstarts has some samples and MSDN Online has extensive documentation.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Tarun Mistry" wrote:
Many thanks Bruce, problem solved. However a further question to increase my understanding, why does a namespace object have to be given to the
SelectSingleNod e member before executing?

i.e.

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nsmgr.AddNamesp ace("xsi", http://www.w3.org/2001/XMLSchema-instance);

what does this achieve?

Thanks again,
Taz

Dec 3 '05 #6
Many thanks everyone!

I really appreciate your help and input.

Everything is much clearer now.

Kind regards
Tarun
Dec 3 '05 #7

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

Similar topics

6
3403
by: Newbie | last post by:
I am doing some robotics projects but my main area of interest is trying out several algorithms for the processing of the stream of data coming from the video. I am wondering what type of camera I should invest in. Either I could buy a web cam and hope I can find a driver I could either modify or use. i.e. every frame is somehow stored on the computer automagically or I could buy a camera not unlike the AVRcam...
4
8104
by: gl | last post by:
I have just started a project that's going to do very heavy credit card processing through asp.net and i had some questions. I've never really done any cc processing through code and I wasn't sure where to get started. Can anyone suggest a particular gateway or cc processor? I saw a component called ..net charge that seems really promising, has anyone used it? Have any of you done a full e-commerce site and have some suggestions? What is...
0
1980
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing' comes, followed by the 64 bit compilation of the IDl file. The comlpilation goes thro' the full stage and then the StdAfx.cpp is compiled. I have another similar VC 6 COM dll code that gets compiled without invoking the 64 bit processing of the...
2
1497
by: Luiz Vianna | last post by:
Hi folks, I got a problem that certainly someone had too. After a user request, I (my server) must process a lot of data that will expend some time. During this process I must inform the user the status of the overall process. What I'm facing is that my ASPX/vb file that does this long task is completely processed before some response could be given to the user. Result: After filling the form, the user clicks the button and the form...
6
4986
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
2
2018
by: domtam | last post by:
Hi all, Here is what I want: when a user clicks a <asp:button>, its event handler will do some server-side processing and then pop up a windows of another page. As far as I know, if no pop-up blocker is disabled, the button event handler can be something like the following to pop-up a window after server-side processing
4
1577
by: Fao, Sean | last post by:
I'm trying to show an animated image temporarily while the web server is processing a long request. I attempted to use a combination of CSS styles and JavaScript to temporarily hide or show only appropriate portions of the page (e.g. hide the data and show an animated "processing" image while the server is doing work), however, it's not exactly working out the way I had hoped. What's the best way to accomplish this task? Thank you in...
10
5720
by: Enrique Cruiz | last post by:
Hello all, I am currently implementing a fairly simple algorithm. It scans a grayscale image, and computes a pixel's new value as a function of its original value. Two passes are made, first horizontally and second vertically. The problem I have is that the vertical pass is 3 to 4 times slower than the horizontal, although the code is _exactly_ the same in both cases?! The code itself is very simple. There are 2 loops to scan through...
0
17520
ADezii
by: ADezii | last post by:
In the Tip of the Week #19, we demonstrated Transaction Processing, specifically as it applies to DAO (Data Access Objects). In this week's Tip, we'll illustrate how Transaction Processing can be used within the context of ADO (ActiveX Data Objects). Please refer to the Link below if you wish to see an Overview of Transaction Processing, how it is implemented within DAO, or special issues to be aware of when utilizing Transaction Processing in...
0
2015
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) *************************************************************************** Symposium “Image Processing and Data Visualization” 2nd South-East European Conference on Computational Mechanics (SEECCM 2009) Island of Rhodes, Greece, 22-24 June 2009
0
8488
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
8408
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
8932
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...
1
8611
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,...
0
7449
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...
0
5709
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
4230
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
4421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2821
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

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.