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

Add attribute to node created using CreateElement

Hi,
How can I add an attribute (called tag) to a node that I've added to an xml
document using the CreateElement method.
My code is as follows:
XmlDocument doc1 = new XmlDocument();

XmlDeclaration dec = doc1.CreateXmlDeclaration("1.0", "", "yes");

doc1.PrependChild ( dec );

XmlNode cont = doc1.CreateElement("Container");

doc1.AppendChild(cont);

Thanks in advance.
Nov 11 '05 #1
1 8241
Hi,
I don't see 'SetAttric=bute' in the intellisense list, however inspite of
that if i add the code specified by you and compile the project I get the
following error - System.xml.xmlnode does not contain a definition for
setattribute. Should I add any assembly reference(I am using VS 1.1)
Thanks in advance.

"Oleg Tkachenko" <ol***@multiconn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Anita C wrote:
How can I add an attribute (called tag) to a node that I've added to an xml document using the CreateElement method.
My code is as follows:
XmlDocument doc1 = new XmlDocument();

XmlDeclaration dec = doc1.CreateXmlDeclaration("1.0", "", "yes");

doc1.PrependChild ( dec );

XmlNode cont = doc1.CreateElement("Container");

XmlElement cont = doc1.CreateElement("Container");
cont.SetAttribute("tag", "foo");

doc1.AppendChild(cont);


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

Nov 11 '05 #2

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

Similar topics

2
by: anon | last post by:
I'm aware that you can assign a value to an attribute in all class instances by assigning to <Class>.<attribute>, however, my case is slightly different and bizarre. In module node: top,...
1
by: davisjoseph | last post by:
Hi, I'm using Xerces C++ API for XML operations. I need to remove the XML namespace attribute from this type of XML doc, <?xml version="1.0" encoding="UTF-8"?> <root...
1
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. ...
2
by: Urs Vogel | last post by:
Hi When using XmlDocument, I can create nodes and attributes as I like. What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node...
0
by: pvssvikas | last post by:
Good Afternoon, I'am badly in need of help. My task :--- I would like to create a node set of elements through C++ code while executing a style sheet and process the created node set. Node...
3
by: Fede | last post by:
Hi everybody, in vb.net I have this code: ...... myNode= XmlDoc.CreateElement("aNode") myAttribute = XmlDoc.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink") ...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
5
by: Soledad Vel | last post by:
Hi All, i write this code: var sliderwidth=100; var sliderheight = 100; var div1 = document.createElement('div'); div1.setAttribute('id','d5'); div1.setAttribute('style',...
4
by: Walton | last post by:
checkout: (3rd paragraph under 'Remarks' section) http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp from the page: "The NAME attribute...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.