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

Changing Node Values



I have the following XML..

<?xml version="1.0" encoding="UTF-8"?>

<EMS>

<Scene>

<Number_of_Patients>1212</Number_of_Patients>

<MCI code_description_type="description">

<Code>Stri</Code>

</MCI>

<Location_Type code_description_type="description">

<Code>Stri</Code>

</Location_Type>

<Service_Type code_description_type="description">

<Code>Stri</Code>

</Service_Type>

</Scene>

</EMS>
using the following Xpath expression ...
//*[@code_description_type='description']//Code

How can I iterate through using C# and change "Stri" to "ABC" ?
Nov 11 '05 #1
6 5577
Mike McCarthy wrote:
How can I iterate through using C# and change "Stri" to "ABC" ?


XmlDocument doc = new XmlDocument();
//Load XML
doc.LoadXml(xml);
XmlNodeList list =
doc.SelectNodes("//*[@code_description_type='description']//Code[.='Stri']");
foreach (XmlNode node in list)
node.FirstChild.Value = "ABC";

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
When I run this I get an exception "Data at the root level is invalid".
Any suggestions?
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eq**************@TK2MSFTNGP11.phx.gbl...
Mike McCarthy wrote:
How can I iterate through using C# and change "Stri" to "ABC" ?
XmlDocument doc = new XmlDocument();
//Load XML
doc.LoadXml(xml);
XmlNodeList list =

doc.SelectNodes("//*[@code_description_type='description']//Code[.='Stri']")
; foreach (XmlNode node in list)
node.FirstChild.Value = "ABC";

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Mike McCarthy wrote:
When I run this I get an exception "Data at the root level is invalid".
Any suggestions?

Most likely you are trying to load XML by URL using LoadXML method. My
mistake, I just tested it loading your XML as string. Use ordinar Load
method instead.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4
Thanks the code runs.

I noticed though that my file has not been changed.

Should I be using XmlWriter ?

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Mike McCarthy wrote:
When I run this I get an exception "Data at the root level is invalid".
Any suggestions?

Most likely you are trying to load XML by URL using LoadXML method. My
mistake, I just tested it loading your XML as string. Use ordinar Load
method instead.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #5
Mike McCarthy wrote:
I noticed though that my file has not been changed.

Sure, you have to save modified document using Save method, e.g.
doc.Save("foo.xml");
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #6
Thank you very much.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Mike McCarthy wrote:
I noticed though that my file has not been changed.

Sure, you have to save modified document using Save method, e.g.
doc.Save("foo.xml");
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #7

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

Similar topics

2
by: mr_burns | last post by:
Hi there, Is it possible to use PHP to change the values of XML nodes in an XML file witout having to extract all the node values, change the variable I want, use PHP to generate the node...
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
0
by: tshad | last post by:
I can add a cookie fine, but I can't seem to figure out how to change the value of a cookie and save it back. My code looks like: if (passwordSaveCookie.checked) then If...
3
by: kurt sune | last post by:
I am running the native debugger in Visual Studio. I debug an assembly calling DLL:s made in VB6. I can watch the values of variables thus: ?Number 0x06e1960c "300115"
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
4
by: Keith Patrick | last post by:
I'm trying to parse some XML via IXPathNavigable, handling elements, text, and attributes with the same code but without having a switch (node.NodeType). However, if I look at a parent element in...
1
by: sathyan8294 | last post by:
what is vb.net code for changing the values in datagrid and save the changed values using vb.net windows application
3
by: srinivasreddypn | last post by:
Hi everybody, Here I am doing a project to generate flash line graphs using xml data. I prepared every thing ready for this, But only problem I am facing since so many days is from the node values...
0
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.