PC Review


Reply
Thread Tools Rate Thread

Adding a XML Attribute for an Exiting Node

 
 
Peter
Guest
Posts: n/a
 
      8th Dec 2003
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




 
Reply With Quote
 
 
 
 
Randy Charles Morin
Guest
Posts: n/a
 
      9th Dec 2003
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.OuterXml);
}

Hope this helps,

Randy
http://www.kbcafe.com

"Peter" <(E-Mail Removed)> wrote in message news:<f79b01c3bddf$8f26d7b0$(E-Mail Removed)>...
> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Treeview : Adding a node to a specific existing node with Net 1.0(work with 2.0) michelqa@yahoo.ca Microsoft C# .NET 2 12th Jun 2008 08:18 AM
strange problem adding child node to a parent node =?Utf-8?B?TXJOb2JvZHk=?= Microsoft C# .NET 3 11th Jan 2005 08:25 AM
XPath to get a node with a certain attribute value =?Utf-8?B?Sm9u?= Microsoft Dot NET Framework 3 19th Feb 2004 02:00 AM
adding a node to a parent node in a tree view Brian Henry Microsoft VB .NET 3 18th Jan 2004 04:24 AM
Having exiting node reboot after cluster failover John Theune Microsoft Windows 2000 Advanced Server 1 25th Oct 2003 01:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 AM.