tags:

views:

108

answers:

2
<?xml version="1.0" encoding="utf-8" ?>

<NickContents>
    <Nick id="test" password="test1" />
    <Nick id="test2" password="test1" />
    <Nick id="nKm4T5c1UQKyfyVPscL99w==" password="nKm4T5c1UQKyfyVPscL99w==" />
    <Nick id="zrtcPuJwJLYtQYzyLqYXYA==" password="i+n+EXfFKHAMsCafvn1uiQ==" />
    <Nick id="Utn83sH6g1/8IO7GeE9NSA==" password="pnloAHE/nagl2kw23L+BsA==" />
</NickContents>

how to delete where id = test?

A: 

Using XmlDocument as an example, and treating id as an attribute:

XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<xml>
  <row id='123'/>
  <row id='456'/>
  <row id='789'/>
</xml>");
XmlNode node = doc.SelectSingleNode("//row[@id=456]");
node.ParentNode.RemoveChild(node);
string s = doc.OuterXml;
Marc Gravell
XmlDocument d = new XmlDocument(); d.Load(File); XmlNode t = d.SelectSingleNode("/NickContents[@id='test']"); t.ParentNode.RemoveChild(t); d.Save(File); ?
monkey_boys
That isn't a question... But reading between the lines: "/NickContents/Nick[@id='test']", or "//Nick[@id='test']"
Marc Gravell
+3  A: 

You could try this:

XmlDocument d = new XmlDocument();
d.Load("MyFileName.Xml");

XmlNode t = d.SelectSingleNode("/path/to/node[@id='test']");
t.ParentNode.RemoveChild(t);

d.Save();
Mr. Smith
dot net 2 how to?
monkey_boys
Error 1 No overload for method 'Save' takes '0' arguments C:\Users\Admin\Desktop\DigALL\Nick.cs 63 13 MoodigX
monkey_boys
Object reference not set to an instance of an object.
monkey_boys
Re the save - give it a path, then. Re the object reference; you need to change "/path/to/node[@id='test']" to fit your xml... in the xml edited into the question, it would be "/NickContents/Nick[@id='...']", where the ... is your id.
Marc Gravell