473,513 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to generate XML file as follow, using XmlDocument.

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

< Employee EID=”222” Description=” abc”>
<Dept DeptNo=”D10”>
<FirstNameSwapnil </FirstName>
<LastNameChavan </LastName>
</Dept>
</Employee>
</Company>
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
position.
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 1096
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 =
"Abhijit";

dept.AppendChild(doc.CreateElement("LastName")).In nerText = "Babar";
}
}
string xml = doc.OuterXml;
// find employee...
XmlElement foundEmp = (XmlElement)doc.SelectSingleNode("/
Company/Employee[@EID='111']");
// remove employee..
foundEmp.ParentNode.RemoveChild(foundEmp);
Jun 27 '08 #2

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

Similar topics

1
2329
by: Tim:. | last post by:
Hi Can someone tell me how I generate a new XML file that I can then use with an XSLT file. I am trying to use an XML file generated from Microsoft Project or even better generate an XML file from...
2
5054
by: brad | last post by:
I have an XMLDocument that my web page downloads and manipulates as a response to user input. I have lots of JavaScript that acts as a controller between my view (html) and my model (xml). That...
5
1988
by: Dario de Judicibus | last post by:
I am trying to generate an XML file to be shown in IE by javascript. My code looks like top.x = window.open('','MyXML') ; top.x.document.write('<?xml version="1.0" encoding="ISO-8859-1" ?>') ;...
6
1550
by: Paul M | last post by:
hi there, i have an xml file, but am not too sure how to read all these elements using vb.net code. any help would be greatly appreciated:)) <---------CODE---------------> <?xml...
4
2066
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
4
2050
by: SteveW | last post by:
Thanks to some good help from a previous post, I have been able to create well formed xml as part of a report logger app. However, I still have a small problem. When I add new xml to the log file,...
6
7252
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem :...
1
1530
by: Abhijit D. Babar | last post by:
Hello, I have to generate XML file as follow, using XmlDocument. <Company> < Employee EID=”111” Description=” xyz”> <Dept DeptNo=”D10”> <FirstNameAbhijit </FirstName> <LastNameBabar...
0
1256
by: Abhijit D. Babar | last post by:
Hello, I have to generate XML file as follow, using XmlDocument. <Company> < Employee EID=”111” Description=” xyz”> <Dept DeptNo=”D10”> <FirstNameAbhijit </FirstName> <LastNameBabar...
6
2961
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
0
7175
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
7391
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,...
0
7553
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
7542
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...
1
5100
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...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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...

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.