Hi,
I have an XML document and I need to add some attributes to an element.
I use the XMLDocument object to load the xml file, and I can get the
element I need to add attributes to in an XMLNode. The problem is, it
seems that I cannot create a new XmlAttribute, it has no constructor.
Does anyone have any idea how I can do this? I would appreciate your
help. Thanks.
fix. 8 3208
fix wrote: I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an XMLNode. The problem is, it seems that I cannot create a new XmlAttribute, it has no constructor.
What about XmlElement.SetAttribute() method?
--
Oleg Tkachenko [XML MVP, MCAD] http://www.xmllab.net http://blog.tkachenko.com
Hello! I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an XMLNode. The problem is, it seems that I cannot create a new XmlAttribute, it has no constructor. Does anyone have any idea how I can do this? I would appreciate your help. Thanks.
You don't use the constructors of XmlNode (and classes that inherit from
it). You have to create the objects using the
XmlDocument.CreateXXX-Methods (like CreateTextNode, CreateElement,...)
and then add them to the Tree.
--
Pascal Schmitt
Oh yes, XmlElement object works for me. I was just looking into
XmlNode...... But what's the different between this two? Is XmlElement
only for a "tag" but XmlNode can point to "tags", attributes, etc?
Thanks.
fix.
Oleg Tkachenko [MVP] wrote: fix wrote:
I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an XMLNode. The problem is, it seems that I cannot create a new XmlAttribute, it has no constructor.
What about XmlElement.SetAttribute() method?
Pascal Schmitt wrote: Hello!
I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an XMLNode. The problem is, it seems that I cannot create a new XmlAttribute, it has no constructor. Does anyone have any idea how I can do this? I would appreciate your help. Thanks.
You don't use the constructors of XmlNode (and classes that inherit from it). You have to create the objects using the XmlDocument.CreateXXX-Methods (like CreateTextNode, CreateElement,...) and then add them to the Tree.
I wasn't too sure about the difference between XmlNode and XmlElement. I
am now using XmlElement.SetAttribute and it works. Anyway, thanks.
fix.
fix wrote: Oh yes, XmlElement object works for me. I was just looking into XmlNode...... But what's the different between this two? Is XmlElement only for a "tag" but XmlNode can point to "tags", attributes, etc?
Well, XmlElement is for element nodes, XmlAttribute is for attribute
nodes, XmlText is for text nodes and so on. XmlNode is a common base
class for all those type of nodes. Thus each instance of XmlElement is
also an instance of XmlNode but not the other way round.
The markup of elements consists e.g. of start and end "tag" and the
contents in between
<god>Kibo</god>
but in the object model there is nothing called "tags", there are nodes
of different types where one type is XmlElement for element nodes.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
XmlDocument xmlDoc = new XmlDocument();
XmlNode xmlNode;
// .. some code to create XML doc
xmlNode = xmlDoc.SelectSingleNode("<some XPath expression>");
xmlChild = (XmlElement)xmlNode;
xmlChild.SetAttribute("name", "value");
HTH,
Stefan
"fix" <fi*@here.com> schrieb im Newsbeitrag
news:eh*************@tk2msftngp13.phx.gbl... Hi,
I have an XML document and I need to add some attributes to an element. I use the XMLDocument object to load the xml file, and I can get the element I need to add attributes to in an XMLNode. The problem is, it seems that I cannot create a new XmlAttribute, it has no constructor. Does anyone have any idea how I can do this? I would appreciate your help. Thanks.
fix.
Hello! Oh yes, XmlElement object works for me. I was just looking into XmlNode...... But what's the different between this two? Is XmlElement only for a "tag" but XmlNode can point to "tags", attributes, etc?
Well, XmlElement is for element nodes, XmlAttribute is for attribute nodes, XmlText is for text nodes and so on. XmlNode is a common base class for all those type of nodes. Thus each instance of XmlElement is also an instance of XmlNode but not the other way round.
The markup of elements consists e.g. of start and end "tag" and the contents in between <god>Kibo</god> but in the object model there is nothing called "tags", there are nodes of different types where one type is XmlElement for element nodes.
This is an interesting introduction (and a core reference...):
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/introduction.html>
--
Pascal Schmitt
Pascal Schmitt wrote: Hello!
Oh yes, XmlElement object works for me. I was just looking into XmlNode...... But what's the different between this two? Is XmlElement only for a "tag" but XmlNode can point to "tags", attributes, etc?
Well, XmlElement is for element nodes, XmlAttribute is for attribute nodes, XmlText is for text nodes and so on. XmlNode is a common base class for all those type of nodes. Thus each instance of XmlElement is also an instance of XmlNode but not the other way round.
The markup of elements consists e.g. of start and end "tag" and the contents in between <god>Kibo</god> but in the object model there is nothing called "tags", there are nodes of different types where one type is XmlElement for element nodes.
This is an interesting introduction (and a core reference...):
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/introduction.html>
All right guys, thanks a lot. Now I have a clearer picture.
fix. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John L. Clark |
last post by:
I am curious as to the rationale, and effect, of having default
namespaces not applying (directly) to attributes (see
http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute
without a...
|
by: Jordan Willms |
last post by:
Hi there.
I am working with lom metadata and I am a little confused with how to
form the following xml element:
<lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2"...
|
by: Amir Hardon |
last post by:
I'm new to DOM and can't figure out this thing:
I'm trying to add a row to a table with a form field in one
of it's cells, but if I'm appending the field to a form
it gets out of the table. Can...
|
by: Melissa Mussitsch |
last post by:
I've done this before while creating a brand new table.
But the code below is not working and I keep getting the error:
"Internet Explorer cannot open the Internet site .....
Operation aborted"
...
|
by: Maersa |
last post by:
hi,
i'm trying to add "attributes" to some nodes and it works at design time but
fails at runtime.
XmlDocument doc = new XmlDocument();
XmlElement elem = doc.CreateElement( "root" );...
|
by: Ian Collins |
last post by:
Is there a way to do this in IE?
In Firefox, one can simply append a node from an XML return to the
current document. IE whinges about 'No such interface supported'
--
Ian Collins.
|
by: Muzzy |
last post by:
Hi,
I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
|
by: Water Cooler v2 |
last post by:
I know that we can add a single name value entry in app.config or
web.config in the configuration/configSettings/appSettings section like
so:
<add key="key" value="value" />
Question: I want...
|
by: paul.boparai |
last post by:
Hi,
I have an element that I would like to add to the docbook DTD. This
element is a wrapper element that I would like to wrap all of the
standard docbook elements. This element is called...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |