473,498 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a XML Attribute for an Exiting Node

Hi,
If I use the following code, there is a attribute.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item id='301'>Pink Ale Beer</item>");

If I code the 2nd line as below:
doc.LoadXml("<item>Pink Ale Beer</item>");
My question is how to add the attribute after that.
Please advice. Thanks.
Peter


Nov 22 '05 #1
2 1234
Sample
static void Main(string[] args)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<item>Pink Ale Beer</item>");
doc.DocumentElement.SetAttribute("id", "301");
System.Console.WriteLine(doc.DocumentElement.Outer Xml);
}

Hope this helps,

Randy
http://www.kbcafe.com

"Peter" <an*******@discussions.microsoft.com> wrote in message news:<f7****************************@phx.gbl>...
Hi,
If I use the following code, there is a attribute.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item id='301'>Pink Ale Beer</item>");

If I code the 2nd line as below:
doc.LoadXml("<item>Pink Ale Beer</item>");
My question is how to add the attribute after that.
Please advice. Thanks.
Peter

Nov 22 '05 #2
Sample
static void Main(string[] args)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<item>Pink Ale Beer</item>");
doc.DocumentElement.SetAttribute("id", "301");
System.Console.WriteLine(doc.DocumentElement.Outer Xml);
}

Hope this helps,

Randy
http://www.kbcafe.com

"Peter" <an*******@discussions.microsoft.com> wrote in message news:<f7****************************@phx.gbl>...
Hi,
If I use the following code, there is a attribute.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item id='301'>Pink Ale Beer</item>");

If I code the 2nd line as below:
doc.LoadXml("<item>Pink Ale Beer</item>");
My question is how to add the attribute after that.
Please advice. Thanks.
Peter

Nov 22 '05 #3

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

Similar topics

1
256
by: Peter | last post by:
Hi, If I use the following code, there is a attribute. XmlDocument doc = new XmlDocument(); doc.LoadXml("<item id='301'>Pink Ale Beer</item>"); If I code the 2nd line as below:...
0
255
by: Peter | last post by:
Hi, If I use the following code, there is a attribute. XmlDocument doc = new XmlDocument(); doc.LoadXml("<item id='301'>Pink Ale Beer</item>"); If I code the 2nd line as below:...
3
27300
by: Andy | last post by:
Hello Guys: What am I doing wrong with this code? I can't seem to get it to simply add an attribute to my node. The node already exists. I am simply opening the XMLDocument and creating one...
11
2277
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to add the following attributes (xmlns:xsi and xsi:type) to a node (Grantee) like the following: <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">...
0
7125
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
7002
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
7203
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
7379
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...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.