471,337 Members | 882 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to generate XML file as follow, using XmlDocument.

I have to generate XML file as follow, using XmlDocument.
< Employee EID=111 Description= xyz>
<Dept DeptNo=D10>
<FirstNameAbhijit </FirstName>
<LastNameBabar </LastName>
<Dept DeptNo=D20>
<FirstNameSahine </FirstName>
<LastNameGhavane </LastName>

< Employee EID=222 Description= abc>
<Dept DeptNo=D10>
<FirstNameSwapnil </FirstName>
<LastNameChavan </LastName>
I have to add Dept node at runtime and not fix number, Dept node added
will be between 1 to 10. Sometimes I will add 2 Dept nodes;
sometimes I will add 10 Dept nodes. New node will append at the end
Also I have to search Employee node from its EID, and Delete
particular node from EID.
Also all Dept node will be display when we select Particular EID from
Employee Node

How can I do this. Please give me hint. Thanks

Jun 27 '08 #1
1 1019
This should get you started...

XmlDocument doc = new XmlDocument();
XmlElement root =
(XmlElement)doc.AppendChild(doc.CreateElement("Com pany"));
// loop over employees...
XmlElement emp =
(XmlElement)root.AppendChild(doc.CreateElement("Em ployee"));
emp.SetAttribute("EID", "111");
emp.SetAttribute("Description", "xyz");
// loop over depts
XmlElement dept =
(XmlElement)emp.AppendChild(doc.CreateElement("Dep t"));
dept.SetAttribute("DeptNo", "D10");

dept.AppendChild(doc.CreateElement("FirstName")).I nnerText =

dept.AppendChild(doc.CreateElement("LastName")).In nerText = "Babar";
string xml = doc.OuterXml;
// find employee...
XmlElement foundEmp = (XmlElement)doc.SelectSingleNode("/
// remove employee..
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tim:. | last post: by
2 posts views Thread by brad | last post: by
5 posts views Thread by Dario de Judicibus | last post: by
1 post views Thread by Abhijit D. Babar | last post: by
reply views Thread by Abhijit D. Babar | last post: by
6 posts views Thread by =?Utf-8?B?RGF2aWRN?= | last post: by
reply views Thread by rosydwin | 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.