By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,494 Members | 914 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,494 IT Pros & Developers. It's quick & easy.

Find and replace the value of node type that is Text

P: n/a
ryu
Hi all,

I have a xml document where I have to replace the value of node type that is
text.
For example,

if the value of a node whose type is 'text' is 'Toyota', I would like it to
be replaced with 'Honda'.

Is there a way to do this?

Thanks
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


ryu wrote:

I have a xml document where I have to replace the value of node type that is
text.
For example,

if the value of a node whose type is 'text' is 'Toyota', I would like it to
be replaced with 'Honda'.

Is there a way to do this?


Sure
textNode.Value = "Honda"
or
textNode.Data = "Honda"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

P: n/a
ryu
But how do you iterate the series of nodes to find Honda? If I use a reader
as XmlTextReader , the reader's value property wouldn't allow me to set. If
I load the xml into a XmlDocument, I dont see any methods that will iterate
the series of nodes. Please advice.
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...


ryu wrote:

I have a xml document where I have to replace the value of node type that
is text.
For example,

if the value of a node whose type is 'text' is 'Toyota', I would like it
to be replaced with 'Honda'.

Is there a way to do this?


Sure
textNode.Value = "Honda"
or
textNode.Data = "Honda"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

P: n/a


ryu wrote:
But how do you iterate the series of nodes to find Honda? If I use a reader
as XmlTextReader , the reader's value property wouldn't allow me to set. If
I load the xml into a XmlDocument, I dont see any methods that will iterate
the series of nodes.


In the DOM as implemented by XmlDocument a text node is always a child
node of an element node so you could use GetElementsByTagName to find
the elements you are looking for to contain the text.
Or you can use XPath e.g.
XmlNodeList nodeList =
xmlDocument.SelectNodes("//text()[. = 'Toyota']");
foreach (XmlNode node in nodeList) {
nodeList.Value = "Honda";
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4

P: n/a
ryu
That should solve the problem. Thanks!

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...


ryu wrote:
But how do you iterate the series of nodes to find Honda? If I use a
reader as XmlTextReader , the reader's value property wouldn't allow me
to set. If I load the xml into a XmlDocument, I dont see any methods that
will iterate the series of nodes.


In the DOM as implemented by XmlDocument a text node is always a child
node of an element node so you could use GetElementsByTagName to find the
elements you are looking for to contain the text.
Or you can use XPath e.g.
XmlNodeList nodeList =
xmlDocument.SelectNodes("//text()[. = 'Toyota']");
foreach (XmlNode node in nodeList) {
nodeList.Value = "Honda";
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.