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

How to add new node with value?

I want to create new node, and then save it to file.
I can add empty node with attributes, but I don't know how set new value for
the node:
String *strMake = this->txtMake->Text;
String *strModel = this->txtModel->Text;
XmlDocument* XmlDoc = new XmlDocument();

try {
// Get the XML file and load it in the XmlDocument variable
XmlDoc->Load(S"c:\\cars.xml");

// Create the new element
XmlElement *Elm = XmlDoc->CreateElement(S"car");

// Create its attributes
Elm->SetAttribute(S"Make", strMake);
Elm->SetAttribute(S"Model", strModel);

// I try set value like this :
Elm->Value="myvalue";
//but I get message :
// "Cannot set a value on node type : Element."

// Add the new element to the file...
XmlDoc->DocumentElement->AppendChild(Elm);
// ... and save the document
XmlDoc->Save(S"c:\\cars.xml");
}
Nov 12 '05 #1
5 12124
* Lupina wrote in microsoft.public.dotnet.xml:
I want to create new node, and then save it to file.
I can add empty node with attributes, but I don't know how set new value for
the node:


I assume you want to have something like <foo>text</foo>? The "text"
in this example is a text node which generally needs to be created
separately and then appended to the foo element node, see e.g. the
documentation on System.Xml.XmlText.
Nov 12 '05 #2
It works :

.......
XmlText *text = XmlDoc->CreateTextNode("myValue");

XmlDoc->DocumentElement->AppendChild(Elm);

XmlDoc->DocumentElement->LastChild->AppendChild(text);

........

Great Thanks !
Nov 12 '05 #3
See also this example of mine:

http://weblogs.asp.net/sonukapoor/articles/132945.aspx

Sonu Kapoor
Blog: http://weblogs.asp.net/sonukapoor

-----Original Message-----
It works :

.......
XmlText *text = XmlDoc->CreateTextNode("myValue");

XmlDoc->DocumentElement->AppendChild(Elm);

XmlDoc->DocumentElement->LastChild->AppendChild(text);

........

Great Thanks !
.

Nov 12 '05 #4
You can also use XmlElement.InnerText to set its value.

--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com

"Lupina" <lu****@op.pl> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
It works :

......
XmlText *text = XmlDoc->CreateTextNode("myValue");

XmlDoc->DocumentElement->AppendChild(Elm);

XmlDoc->DocumentElement->LastChild->AppendChild(text);

.......

Great Thanks !

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 23/05/2004
Nov 12 '05 #5
You can also use XmlElement.InnerText to set its value.

--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com

"Lupina" <lu****@op.pl> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
It works :

......
XmlText *text = XmlDoc->CreateTextNode("myValue");

XmlDoc->DocumentElement->AppendChild(Elm);

XmlDoc->DocumentElement->LastChild->AppendChild(text);

.......

Great Thanks !

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 23/05/2004
Nov 12 '05 #6

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

Similar topics

3
by: keepyourstupidspam | last post by:
Hi, I am using xerces dom C++, I want to change an element value, here is the code I am using but the element in the file is not getting updated. ... ... ... xercesc_2_4::DOMDocument*...
3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Keith M | last post by:
Hi, I have found a very useful piece of code in the msdn which shows how to load an xml config file, search for a particular value and replace it. Could someone possibly convert it to C# from...
5
by: Matt | last post by:
I need help with passing a generated node set from a style sheet into my customer msxsl extension. I have the following node set that I am creating: <xsl:variable name="sql"> <SQL>...
1
by: Dica | last post by:
hi all first off, i'm not trying to cross post, but couldn't find this newsgroup earlier (got here from a recommendation on microsoft.public.vb, where i originally posted this question). ...
0
by: XML newbie: Urgent pls help! | last post by:
ok, I changed "If node.Text = "Success" " to "If Not loginDom.InnerText Is Nothing ". Now, I don't get the NullReference error but the SessionID I see on screen is concatanated one. It looks...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
0
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.