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

Beginners Question...

I got a XML file like this:

<?xml version="1.0" encoding="utf-16"?>
<LicenceControlFile>
<Licence1>2AB7-FA43-B05C-4C2A-8DBD</Licence1>
<MachineName />
<Licence2>2AB7-FA43-B05C-4C2A-8DBD</Licence2>
<MachineName />
<Licence3>2AB7-FA43-B05C-4C2A-8DBD</Licence3>
<MachineName />
</LicenceControlFile>

Now i need to set the Value of one of the <MachineName /> Elements !
How can i do this with .NET...

Thanks

Peter
Nov 11 '05 #1
3 2346
Peter Treier wrote:
<?xml version="1.0" encoding="utf-16"?>
<LicenceControlFile>
<Licence1>2AB7-FA43-B05C-4C2A-8DBD</Licence1>
<MachineName />
<Licence2>2AB7-FA43-B05C-4C2A-8DBD</Licence2>
<MachineName />
<Licence3>2AB7-FA43-B05C-4C2A-8DBD</Licence3>
<MachineName />
</LicenceControlFile>

Now i need to set the Value of one of the <MachineName /> Elements !
How can i do this with .NET...


The simplest (but not necessarily the most effective) way is to load document
to XmlDocument, select appropriate MachineName element using SelectSingleNode
method, update it and save document back.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Good evening Oleg

I've tried to do that, but i got one Error

<---Error

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: Cannot set a value on node type: Element.

--->End Error

I've selected the first Element with Xpath
loDoc is a XMLDocument

loDoc.SelectSingleNode("/LicenceControlFile/MachineName").Value =
sMachineName

Whats wrong ?

Regards from Switzerland

Peter

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eD*************@TK2MSFTNGP11.phx.gbl...
Peter Treier wrote:
<?xml version="1.0" encoding="utf-16"?>
<LicenceControlFile>
<Licence1>2AB7-FA43-B05C-4C2A-8DBD</Licence1>
<MachineName />
<Licence2>2AB7-FA43-B05C-4C2A-8DBD</Licence2>
<MachineName />
<Licence3>2AB7-FA43-B05C-4C2A-8DBD</Licence3>
<MachineName />
</LicenceControlFile>

Now i need to set the Value of one of the <MachineName /> Elements !
How can i do this with .NET...
The simplest (but not necessarily the most effective) way is to load

document to XmlDocument, select appropriate MachineName element using SelectSingleNode method, update it and save document back.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Peter Treier wrote:

I've tried to do that, but i got one Error

<---Error

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: Cannot set a value on node type: Element.

--->End Error

I've selected the first Element with Xpath
loDoc is a XMLDocument

loDoc.SelectSingleNode("/LicenceControlFile/MachineName").Value =
sMachineName

Whats wrong ?


Forgot to mention, you have to create text node. In DOM elements have no
value. Text is stored in text nodes' value. So you have to create text node,
set its value and append it as a child to the element.
Something like
XmlNode elem = loDoc.SelectSingleNode("/LicenceControlFile/MachineName");
XmlText textNode = loDoc.CreateTextNode(sMachineName);
elem.AppendChild(textNode);

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

Nov 11 '05 #4

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

Similar topics

7
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional...
4
by: blah | last post by:
I m actually a Novice in Python as well as Linux, When i look up things on the internet about Linux Flavours, They are written so complex that it is difficult for me to understand, i am asking if...
4
by: Eggnog | last post by:
Hi, Is there a newsgroups for beginners questions? Cheers, Nawg
6
by: William Foster | last post by:
Does anyone know of a good online tutorial for C# focused on beginners. I have been to many great sites like csharpfriends, csharp-corner etc looking for good tutorials and have had no luck. Any...
18
by: John Salerno | last post by:
Hi all. I was hoping some of you could recommend a book or two that would help me get started with the basics of C#. I have a slight knowledge of programming, but basically I want to start out like...
2
by: =?Utf-8?B?UmFrZXNo?= | last post by:
Hi, I have worked in Windows development for some time and want to learn ASP.Net - Web Application. Can some one redirect me to some site where I can find some good start up for beginners course...
4
by: aman firoz | last post by:
do you people got anything for c beginners..... help me out guys
0
by: Dual_b00t | last post by:
hi i created a site called PHP Together its for beginners also for gurus to help out the beginners if you are learning PHP and feel alone then drop by . ciao Mark
19
by: yltkhuu | last post by:
1. How does having a widely adopted C++ standard help game programmers? 2. What are the advantages ans disadvantages of employing the "using" directive? 3. Why might you define a new name for an...
6
by: Lars | last post by:
Hi all If this is the wrong list for beginners trouble I apologize. please refer to me the correct list in such case. I am trying to create a simple linked list but I keep getting segmentation...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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.