Click here to Skip to main content
15,893,564 members
Home / Discussions / C#
   

C#

 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
jinzhecheng18-May-05 5:04
jinzhecheng18-May-05 5:04 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
Marc Clifton18-May-05 5:41
mvaMarc Clifton18-May-05 5:41 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
S. Senthil Kumar18-May-05 5:48
S. Senthil Kumar18-May-05 5:48 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
jinzhecheng18-May-05 6:21
jinzhecheng18-May-05 6:21 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
Marc Clifton18-May-05 6:53
mvaMarc Clifton18-May-05 6:53 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
18-May-05 6:59
suss18-May-05 6:59 
GeneralRe: real challenge! How to implicitly override a Win form method Pin
DavidNohejl18-May-05 6:55
DavidNohejl18-May-05 6:55 
Generaldeleting particular node element from xml file through LOOP Pin
ksanju100018-May-05 4:13
ksanju100018-May-05 4:13 
Hi
I want to delete the particular node from xml file
Supoose i want to delete farm name="ram" it should delete all the contents of element farm
Program should search from the file for particular node and delete
I have written the code for deleting but it deletes from UPPer node only it deletes ram what ever you give the farm name dev2.
my code is given below pls modify it
private void button15_Click(object sender, System.EventArgs e)
{

strtxt_BD_farmName="dev1";

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("c:/farm-config.xml");
XmlNodeList farm=xmldoc.SelectNodes("//farm");



foreach(XmlNode n in farm)
{
if (n.Attributes.GetNamedItem("name").Value == strtxt_BD_farmName)
{

MessageBox.Show("Enter Farm name found");


XmlNode xNode;
XmlElement xElmntFamily;

// Search for a particular node
xNode = xmldoc.SelectSingleNode("//farm-config");

if (!(xNode == null))
{

xElmntFamily = (XmlElement) (xNode);
xElmntFamily.RemoveChild(xElmntFamily.SelectSingleNode("farm"));

FileStream fsxml = new FileStream("c:/farm-config.xml",FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
xmldoc.Save(fsxml);
fsxml.Close();
//xNode=null;
farm=null;


//xmldoc.Save("c:/farm-config.xml");
MessageBox.Show(strtxt_BD_farmName + " deleted");

}



}

}

This is my original XMl structure
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="ram">
<connection address="localhost" user="ram" password="ram">
<lastjob>Copy-All</lastjob>
<lastconnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
<database start="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</connection>
</farm>
<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>

after deletetion my xml structure will look like in the given format but according to my program it is deleteing
farm name=ram as i should delete farm name=dev2 pls someone give me code for that
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>

<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>

Warm regards,
sanjeev
QuestionAVISaveOptions Invisible Font? Pin
Member 190300618-May-05 4:07
Member 190300618-May-05 4:07 
GeneralSelecting row Index of datagrid Pin
Ashishhere18-May-05 3:34
Ashishhere18-May-05 3:34 
GeneralRe: Selecting row Index of datagrid Pin
Marc Clifton18-May-05 4:17
mvaMarc Clifton18-May-05 4:17 
GeneralComboBox - remove focus Pin
NortonC18-May-05 2:05
NortonC18-May-05 2:05 
GeneralRe: ComboBox - remove focus Pin
Marc Clifton18-May-05 2:12
mvaMarc Clifton18-May-05 2:12 
GeneralRe: ComboBox - remove focus Pin
NortonC18-May-05 2:19
NortonC18-May-05 2:19 
GeneralProject Type in VS 2005 Pin
rathishps18-May-05 1:05
rathishps18-May-05 1:05 
GeneralGet High Byte of Int16 Pin
zuschauer198018-May-05 0:32
zuschauer198018-May-05 0:32 
GeneralRe: Get High Byte of Int16 Pin
Marc Clifton18-May-05 1:11
mvaMarc Clifton18-May-05 1:11 
GeneralRe: Get High Byte of Int16 Pin
S. Senthil Kumar18-May-05 1:21
S. Senthil Kumar18-May-05 1:21 
GeneralRe: Get High Byte of Int16 Pin
Mike Dimmick18-May-05 1:42
Mike Dimmick18-May-05 1:42 
Generaltwo's complement Pin
zuschauer198018-May-05 1:46
zuschauer198018-May-05 1:46 
GeneralRe: two's complement Pin
Sebastian Schneider18-May-05 3:50
Sebastian Schneider18-May-05 3:50 
GeneralRe: two's complement Pin
zuschauer198018-May-05 22:49
zuschauer198018-May-05 22:49 
GeneralCheckedListBoxes Pin
17-May-05 23:19
suss17-May-05 23:19 
GeneralRe: CheckedListBoxes Pin
Robert Rohde18-May-05 0:34
Robert Rohde18-May-05 0:34 
Generaldeleting particular node element from xml file Pin
ksanju100017-May-05 23:11
ksanju100017-May-05 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.