471,071 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

HOw To I append the Child Element At any node in the Xml Document.

Hello,

I have created the xml Document through the C# application using XmlTextWriter Class,
Which is as bellow,

<?xml version="1.0" encoding="utf-8" ?>
- <!-- Author HarshaL K. Dhote -->

- <Project Location="C:\WorkSpace">
- <Cars>
C:\WorkSpace\Cars
<HONDA>C:\WorkSpace\Cars\HONDA</HONDA>
</Cars>

<Bikes>C:\WorkSpace\Bikes</Bikes>
<Trucks>C:\WorkSpace\Trucks</Trucks>
<busses>C:\WorkSpace\busses</busses>

</Project>

Suppose Now I have to append child to the node Hond, how should I do this programatically,in C#
Feb 1 '08 #1
1 2103
jkmyoung
2,057 Expert 2GB
Since XmlTextWriter is a forward only XML text writer, you must go to the point where you were writing the Honda node, and write the child node at that point.

If you really want to append it anywhere in the document, I suggest one of 2 options:
1. Load the Xml Document into a tree structure. Make the change with DOM oriented functions. (Safe but slow)
2. Hack it up with a script that finds the given node, and then adds in the specified child node appropriately. (Fast but more dangerous.)
Feb 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by J Krugman | last post: by
10 posts views Thread by Rich Wallace | last post: by
7 posts views Thread by Ward Germonpré | 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.