473,569 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\\car s.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->DocumentElemen t->AppendChild(El m);
// ... and save the document
XmlDoc->Save(S"c:\\car s.xml");
}
Nov 12 '05 #1
5 12129
* Lupina wrote in microsoft.publi c.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.XmlT ext.
Nov 12 '05 #2
It works :

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

XmlDoc->DocumentElemen t->AppendChild(El m);

XmlDoc->DocumentElemen t->LastChild->AppendChild(te xt);

........

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->DocumentElemen t->AppendChild(El m);

XmlDoc->DocumentElemen t->LastChild->AppendChild(te xt);

........

Great Thanks !
.

Nov 12 '05 #4
You can also use XmlElement.Inne rText 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******** ******@TK2MSFTN GP09.phx.gbl...
It works :

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

XmlDoc->DocumentElemen t->AppendChild(El m);

XmlDoc->DocumentElemen t->LastChild->AppendChild(te xt);

.......

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.Inne rText 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******** ******@TK2MSFTN GP09.phx.gbl...
It works :

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

XmlDoc->DocumentElemen t->AppendChild(El m);

XmlDoc->DocumentElemen t->LastChild->AppendChild(te xt);

.......

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
4037
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* xmlDoc = parser->getDocument(); xercesc::DOMNodeList* list;
3
3138
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 since they're not used anymore. But now, I used an <xsl:apply-templates/> and for some reason, it works in some situation but not in others. I...
6
2733
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 2003 - Windows XP Pro PC suscessfully. But when I ran it from the command line - C:\Documents and Settings\SHC\My Documents\Visual Studio...
2
7673
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 the VB I have? I also would like to use similar code to update the machine.config file so if someone could explain how to add a node ("appSettings")...
5
1766
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> <StoredProc>spGetReconID</StoredProc> <Parms> <parm> <name>@tran</name> <value>956</value> </parm>
1
1781
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). anyhow, i'm just getting into .Net and am trying to parse a document, but not able to read the values for the nodes consistently. anybody know what i'm...
0
1156
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 like:XXXXXX=YYYYY==, but did I do wrong. Althouggh, I get the message, Satus as Success.Since, I have to use this SessionID in another click event on the...
0
1486
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), I see it has child nodes, but nodes = Nothing.. Since, I need to copy the value of SessionID in my next function, how can I read the value of Node....
1
2885
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 app.config file is listed below and the code is listed below that, the line with "-->>" is where i try to get the node. Can anyone see where I'm going...
0
3375
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 format every column with a color (e.g. red) if the element value is the same as the one in the next node. if the value changes if should change the color...
0
7711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7628
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7938
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8145
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7694
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.