471,348 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Editing Xml

Hi,

I'm pretty new with XML, and I need to edit a XmlDocument in C#....

now here is an example on what I need.

I have this XMLDocument:

<?xml version="1.0"?>
<root>
<name>John Doe</name>
<conf class="7" uniqueid="1" password="0" />
<userlist>
<users id="1" userid="2" cardid="2"/>
</userlist>
</root>

Ok this is it.... you see the " <users id="1" userid="2" cardid="2"/>"...
that part is supposed to be added by me on the code... and I can't... I would
appreciate some help, hints and/or code snippet to see how can I do it.

Thanks in Advance
Dec 13 '05 #1
1 4347
Diogo Alves - Software Developer
<Di*************************@discussions.microsoft .com> wrote:
I'm pretty new with XML, and I need to edit a XmlDocument in C#....

now here is an example on what I need.

I have this XMLDocument:

<?xml version="1.0"?>
<root>
<name>John Doe</name>
<conf class="7" uniqueid="1" password="0" />
<userlist>
<users id="1" userid="2" cardid="2"/>
</userlist>
</root>

Ok this is it.... you see the " <users id="1" userid="2" cardid="2"/>"...
that part is supposed to be added by me on the code... and I can't... I would
appreciate some help, hints and/or code snippet to see how can I do it.


Well, first create an XmlDocument instance, then load the existing XML,
then find the element you wish to add something into (in this case the
userlist element), then create and add the new element (using
XmlDocument.CreateElement and XmlNode.AppendChild respectively). Set
the attributes you want on the element using XmlElement.SetAttribute.

I would suggest using XPath to find the userlist element - use
XmlNode.SelectSingleNode on the root node of the element, passing in
"/root/userlist" as the XPath expression.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dan Weeb | last post: by
3 posts views Thread by Dirk Rudolf | last post: by
10 posts views Thread by David T. Ashley | last post: by
1 post views Thread by AndrewDucker | last post: by
3 posts views Thread by Islamegy | last post: by
3 posts views Thread by Tina | last post: by
12 posts views Thread by Thomas Bartkus | last post: by
1 post views Thread by Ronak mishra | last post: by

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.