473,396 Members | 2,004 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.

SetAttribute method does not exist for my XmlNode object

I am having trouble creating an Attribute on a new node. The
NodeObject.SetAttribute(x,y) method does not exist for the "RecordElement"
node. What am I missing???

Earl

XmlDocument d = new XmlDocument();

d.Load(savepath);

XmlNode RootNode = d.DocumentElement;
//CREATE THE RECORD NODE

XmlNode RecordElement = d.CreateElement("RECORD");

//RecordElement.SetAttribute(name, value) does not exist here
Nov 11 '05 #1
2 6200
Earl Teigrob wrote:
I am having trouble creating an Attribute on a new node. The
NodeObject.SetAttribute(x,y) method does not exist for the "RecordElement"
node. What am I missing???


XmlNode class has no SetAttribute method, because generic node can't
have attributes. It's only elements who able to bear attributes, so
SetAttribute is XmlElement class's method. Actually CreateElement()
method returns XmlElement and it's you mistake that you are upcasting it
to XmlNode. Use instead:

XmlElement RecordElement = d.CreateElement("RECORD");
RecordElement.SetAttribute(name, value);

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

Nov 11 '05 #2
Thanks, works like a charm...

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eG**************@TK2MSFTNGP12.phx.gbl...
Earl Teigrob wrote:
I am having trouble creating an Attribute on a new node. The
NodeObject.SetAttribute(x,y) method does not exist for the "RecordElement" node. What am I missing???


XmlNode class has no SetAttribute method, because generic node can't
have attributes. It's only elements who able to bear attributes, so
SetAttribute is XmlElement class's method. Actually CreateElement()
method returns XmlElement and it's you mistake that you are upcasting it
to XmlNode. Use instead:

XmlElement RecordElement = d.CreateElement("RECORD");
RecordElement.SetAttribute(name, value);

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

Nov 11 '05 #3

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

Similar topics

31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
0
by: Matthew Copeland | last post by:
A little background. This is a VB.Net client application , and it uses a web reference to a web service, which has been properly refreshed. My app takes collections of two serializable...
6
by: Pugi! | last post by:
I use mycurrent_cell.setAttribute("style", "background-color:green"); and mycurrent_cell.setAttribute("colspan", "3"); to set some attributes of a table. The code works perfect in FireFox and...
4
by: mitch | last post by:
Suppose I have a DOM element, say a td, and I want to add a value to it to be used later. I am unclear on when it's OK to do td.myAttr = "hello"; versus when I need to do ...
4
by: jvanulden | last post by:
Hello all, I am having difficulty figuring out how to create an XmlElement and giving it an attribute that requires a namespace. Here is what I have so far which throws an exception because you...
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
5
by: David Palau | last post by:
I'm looking for some guidance on what data type would work best as the result output of a web service function method. This web method will return an object that implements a class that is...
2
by: bgold12 | last post by:
Does internet explorer support the statement elem.setAttribute('style', ... );, for example: document.getElementById('ExampleID').setAttribute('style', 'width: 10px' ); I can't get that...
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...
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
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
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.