| Brent Jenny 2004-03-28, 10:28 pm |
| I have an xml doc that looks like this.
<?xml version="1.0" encoding="utf-8"?>
<Aircraft>
<WCOJOItemType type="AircraftType" empid="AT03">
<WCJOItemCode>03</WCJOItemCode>
<WCJOItemDescription>B737-700</WCJOItemDescription>
</WCOJOItemType>
<WCJOItemType type="AircrafType" empid="AT77">
<WCJOItemCode>77</WCJOItemCode>
<WCJOItemDescription>777</WCJOItemDescription>
</WCJOItemType>
<WCOJOItemType type="WorkDescription" empid="WD41">
<WCJOItemCode>41</WCJOItemCode>
<WCJOItemDescription>Routine Line</WCJOItemDescription>
</WCOJOItemType>
</Aircraft>
I want to select the <WCJOItemType type="AircrafType" empid="AT77">
node for deletion. I have the following code that works on nodes with
a single attribute but will not find the listed node. I am assuming
that it has somethingto do with having multiple attributes in the
listed node. The line of code that I am having trouble with is line
20.
Please help
1 public void delete_nodes(string id,bool ac)
2 {
3 if(ac)
4 {
5 path = @" C:\inetpub\wwwroot\websceptre_1\xml\wcjo
ac.xml";
6 }
7 else
8 {
9 path = @" C:\inetpub\wwwroot\websceptre_1\xml\wcjo
noac.xml";
10 }
11
12 XmlDocument doc2 = new XmlDocument();
13
14 FileStream docin = new FileStream
(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
15
16 doc2.Load(docin);
17
18 XmlNode root = doc2.DocumentElement;
19
20 XmlElement xNode =
(XmlElement)doc2.SelectSingleNode("/Aircraft/WCOJOItemType[@empid='AT77']");
21 XmlNode adminNode = (XmlNode)xNode;
22 root.RemoveChild(adminNode);
23
24 FileStream docout = new
FileStream(path,FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
25 doc2.Save(docout);
26
27 docout.Close();
28 }
|