473,513 Members | 2,368 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_value_ with some data,

<root>
....
<tag>_replace_with_value_</tag>
....
</root>

What is the process for doing this. I can find the node using
SelectSingleNode, 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 1498
SelectSingleNode 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.SelectSingleNode("root/tag");
tagNode.InnerText = "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
SelectSingleNode member before executing?

i.e.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("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
SelectSingleNode member before executing?

i.e.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("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.SelectSingleNode("//root/firstchild");

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

node.ParentNode.ReplaceChild(node1,node);

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

node.ParentNode.ReplaceChild(doc..ImportNode(node1 ,true), ,node);

HTH,

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
SelectSingleNode 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.SelectSingleNode("root/tag");
tagNode.InnerText = "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*******@yahoo.nospammin.com> wrote in message
news:2F**********************************@microsof t.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
SelectSingleNode member before executing?

i.e.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("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
3390
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...
4
8094
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...
0
1963
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'...
2
1490
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...
6
4962
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...
2
2007
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...
4
1573
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...
10
5691
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...
0
17506
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...
0
2001
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
7175
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...
0
7391
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,...
0
7553
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
5697
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,...
1
5100
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
4754
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
3247
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
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.