473,396 Members | 1,924 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.

Hi I want to Add to an existing xmLDocument an Element . How?

I have An XMLDocument and I want to add a new Element.
I want that the element will be shaped like this :

<event>
<X>1</X>
<Y>2</Y>
</event>

thanks

Dec 21 '06 #1
3 1123
Well, you could start by reading the documentation? I'll give you a
clue...
AppendChild:
http://msdn2.microsoft.com/en-us/lib...pendchild.aspx

Marc
Dec 21 '06 #2
ok
I know that
the problem is the rest..
for example...
XmlElement element = doc.CreateElement( "event" );
XmlNode node1 = doc.CreateNode( "", "X", "" );
node1.InnerText = "1";
XmlNode node2 = doc.CreateNode( "", "Y", "" );
node2.InnerText = "2";
element.AppendChild(node1);
element.AppendChild(node2);

the problem is that it doesnt work
I think I dont build The node correctly

Dec 21 '06 #3
Done 2 ways (note latter includes xml marker, but this can be omitted
by setting the options):

XmlDocument doc = new XmlDocument();
XmlElement root = (XmlElement)
doc.AppendChild(doc.CreateElement("event"));
root.AppendChild(doc.CreateElement("X")).InnerText = "1";
root.AppendChild(doc.CreateElement("Y")).InnerText = "2";
Console.WriteLine(doc.OuterXml);

StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb)) {
writer.WriteStartElement("event");
writer.WriteElementString("X", "1");
writer.WriteElementString("Y", "2");
writer.WriteEndElement();
}
Console.WriteLine(sb);
Dec 21 '06 #4

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

Similar topics

1
by: Andrew Jacobs | last post by:
I am using C# to write an application that migrates documents from one version of an XML schema/DTD to later one. Much of the document has the same structure in the two versions and I use...
8
by: yinjennytam | last post by:
Hi all, I'm new to .NET and XML and I have a question. Given an XML file, I want to navigate its content and look for one or two particular elements to get their values. At this point, it...
4
by: Jesper Stocholm | last post by:
I have a database class that maintains data about customers i my system. The basic XML for this looks like: <Chunk> <Vendor> <Database/> </Vendor> </Chunk> When a user is to be registrered...
1
by: David | last post by:
I need to find a good online resource which teaches the use of the XmlDocument framework in more depth than is covered in MS's online doc. I need to create a multi-level XML document like the one...
3
by: Mungo Jerrie | last post by:
Hi there :-) I have some problems with the same instance of my xmldocument across 3 different classes. See code below: class one { protected static XmlDocument doc = new XmlDocument(); ...
0
by: saish | last post by:
Hello I am new to vb.net webservice. My requirement is to design a VB.net web service which will send and receive xml documents. The xml document send and received would be a very complex .xsd...
5
by: Ron | last post by:
I've got some C# code that sort of does what I want: Looking at the xml files in area: http://www.keepitsimplekid.com/xml I want to change Untitled Ad at the top of the xml to the name of the...
0
by: avolkman | last post by:
I've just begun learning XML and XPATH, so I'm currently at a very beginner level. I have an existing XML file that I would like to add an additional node to before saving it to another variable. The...
2
by: Daljeet Hanspal | last post by:
hi .... i am trying to add a new node to an existing xml file in c# .......... the code is as follows: XmlDocument doc = new XmlDocument(); string filename = @"C:\Documents and...
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
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...
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
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
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...

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.