473,390 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 1494
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
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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
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...

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.