Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
QuestionC# use linq to parse xml Pin
dcof28-Aug-12 17:28
dcof28-Aug-12 17:28 
AnswerRe: C# use linq to parse xml Pin
PIEBALDconsult28-Aug-12 19:21
mvePIEBALDconsult28-Aug-12 19:21 
AnswerRe: C# use linq to parse xml Pin
V.29-Aug-12 2:00
professionalV.29-Aug-12 2:00 
GeneralRe: C# use linq to parse xml Pin
dcof29-Aug-12 10:56
dcof29-Aug-12 10:56 
Questionif webbrowser hangs, then retry, how to check if hanging c# Pin
Member 938944428-Aug-12 13:52
Member 938944428-Aug-12 13:52 
AnswerRe: if webbrowser hangs, then retry, how to check if hanging c# Pin
Shameel28-Aug-12 14:54
professionalShameel28-Aug-12 14:54 
GeneralRe: if webbrowser hangs, then retry, how to check if hanging c# Pin
Member 938944428-Aug-12 16:26
Member 938944428-Aug-12 16:26 
AnswerRe: if webbrowser hangs, then retry, how to check if hanging c# Pin
Shameel28-Aug-12 19:30
professionalShameel28-Aug-12 19:30 
AnswerRe: if webbrowser hangs, then retry, how to check if hanging c# Pin
Eddy Vluggen28-Aug-12 23:09
professionalEddy Vluggen28-Aug-12 23:09 
GeneralRe: if webbrowser hangs, then retry, how to check if hanging c# Pin
Member 88893234-Sep-12 3:52
Member 88893234-Sep-12 3:52 
QuestionSecurity of Passwords Pin
zephaneas28-Aug-12 13:18
zephaneas28-Aug-12 13:18 
AnswerRe: Security of Passwords Pin
jschell28-Aug-12 14:00
jschell28-Aug-12 14:00 
AnswerRe: Security of Passwords Pin
Peter_in_278028-Aug-12 15:13
professionalPeter_in_278028-Aug-12 15:13 
GeneralRe: Security of Passwords Pin
Paul Conrad28-Aug-12 18:24
professionalPaul Conrad28-Aug-12 18:24 
AnswerRe: Security of Passwords Pin
Paul Conrad28-Aug-12 18:25
professionalPaul Conrad28-Aug-12 18:25 
AnswerRe: Security of Passwords Pin
Bernhard Hiller28-Aug-12 21:42
Bernhard Hiller28-Aug-12 21:42 
AnswerRe: Security of Passwords Pin
BobJanova28-Aug-12 23:36
BobJanova28-Aug-12 23:36 
AnswerRe: Security of Passwords Pin
Dave Kreskowiak29-Aug-12 2:06
mveDave Kreskowiak29-Aug-12 2:06 
GeneralRe: Security of Passwords Pin
Eddy Vluggen29-Aug-12 2:24
professionalEddy Vluggen29-Aug-12 2:24 
AnswerRe: Security of Passwords Pin
Pete O'Hanlon29-Aug-12 3:09
mvePete O'Hanlon29-Aug-12 3:09 
QuestionC# create folder and place documents Pin
dcof28-Aug-12 12:05
dcof28-Aug-12 12:05 
AnswerRe: C# create folder and place documents Pin
Richard Andrew x6428-Aug-12 12:57
professionalRichard Andrew x6428-Aug-12 12:57 
AnswerRe: C# create folder and place documents Pin
Wes Aday28-Aug-12 14:49
professionalWes Aday28-Aug-12 14:49 
QuestionDelete From XML File Pin
Kevin Marois28-Aug-12 10:54
professionalKevin Marois28-Aug-12 10:54 
I'v got this contacts file:

<?xml version="1.0" encoding="utf-8"?>
<Contacts>
  <Contact>
    <ContactId>0</ContactId>
    <Prefix>
    </Prefix>
    <FirstName>Kevin</FirstName>
    <MiddleName>Marois</MiddleName>
    <LastName>Brian</LastName>
    <Suffix>
    </Suffix>
    <Birthday>1965-10-11</Birthday>
    <Title>Senior Software Engineer</Title>
    <Comments>has 25 years of development experience</Comments>
  </Contact>
  <Contact>
    <ContactId>1</ContactId>
    <Prefix>Dr.</Prefix>
    <FirstName>Henry</FirstName>
    <MiddleName>DeCarlo</MiddleName>
    <LastName>G</LastName>
    <Suffix>III</Suffix>
    <Birthday>1965-10-11</Birthday>
    <Title>Oral Surgeon</Title>
    <Comments>His office is over on 23rd street</Comments>
  </Contact>
  <Contact>
    <ContactId>2</ContactId>
    <Prefix>
    </Prefix>
    <FirstName>Mattew</FirstName>
    <MiddleName>Damon</MiddleName>
    <LastName>Paige </LastName>
    <Suffix>
    </Suffix>
    <Birthday>1970-10-08</Birthday>
    <Title>Actor</Title>
    <Comments>Excellent actor</Comments>
  </Contact>
</Contacts>


I want to delete a contact given the ContactId. So far I have:

public void DeleteContact(int ContactId)
{
    XmlDocument doc = new XmlDocument();
    doc.Load(XMLFile);
    var path = "/contacts/contact[@ContactId='" + ContactId + "']";
    XmlNode t = doc.SelectSingleNode(path);
    t.ParentNode.RemoveChild(t);
    doc.Save(XMLFile);
}


But this isn't right. What's the right way to do this?

Thanks
If it's not broken, fix it until it is

AnswerRe: Delete From XML File Pin
Richard Andrew x6428-Aug-12 11:10
professionalRichard Andrew x6428-Aug-12 11:10 

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.