473,385 Members | 1,606 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,385 software developers and data experts.

Find and replace the value of node type that is Text

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
4 5518


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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
3
by: =?Utf-8?B?R3JlZyBN?= | last post by:
Hello, I'm running an asp.net, intranet web application using .net framework 1.1 on IIS5.1 / 6.0. Through the web application, I would like to press a button on the web page, have another window...
3
by: Hvid Hat | last post by:
Hi I want to highlight (make it bold) a word in some text I'm getting in XML format. My plan was to replace the word with a bold (or span) tag with the word within the tag. I've found the code...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.