13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

pswd);}}{mustAddNode = false;rw.Writer.WriteStartElement("User");rw.Writer.WriteAttributeStr<strong>in</strong>g("name", name);rw.Writer.WriteAttributeStr<strong>in</strong>g("password",rw.Writer.WriteAttributeStr<strong>in</strong>g("role", role);rw.Writer.WriteEndElement();}elserw.Writer.WriteAttributes(rw.Reader, false);if (rw.Reader.IsEmptyElement)rw.Writer.WriteEndElement();break;// Close the root tagrw.Writer.WriteEndElement();}// Close the document and any <strong>in</strong>ternal resourcesrw.WriteEndDocument();To delete a node, you simply ignore it while read<strong>in</strong>g the document. For example, thefollow<strong>in</strong>g code removes a node <strong>in</strong> which the name attribute matches a specifiedstr<strong>in</strong>g:while(rw.Read()){switch(rw.NodeType){case XmlNodeType.Element:if ("User" == rw.Reader.LocalName){// Skip if name matchesstr<strong>in</strong>g userName = rw.Reader.GetAttribute("name");if (userName == name)break;}// Write <strong>in</strong> the output file if no match has been found159

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!