ISBN = "2-3631-4"> 
 CS from getting started  title>  Waiti  author>  58.3  price>  book>  bookstore> 2, modify Node: Change the GENRE value of the GENRE attribute value to "Update Li Zanli", and modify the text of the child's child's child  to "Ansheng". XmlNodelist NodeList = XmLDoc.selectsinglenode ("BookStore"). ChildNodes; // Get all child nodes for the BookStore node Foreach (XMLNode Xn In nodelist) // Traverse all child nodes {xmlelement XE = (xmlelement) xn; // Fander node Type Convert to XMLELEMENT Type IF (Xe.GetaTRibute ("Genre") == "Li Zanhong") // If the GENRE attribute value is "Li Zanhong" {xe.setttribute ("genre", "Update Li Zan Hong"); // Modify This property is "Update Li Zanli" XMLNodeList NLS = Xe.childNodes; / / Continue all child nodes of the XE child node Foreach (XMLNode XN1 IN NLS) // Traversed {XMLELEMENT XE2 = (XMLELEMENT) XN1; // Conversion Type IF ( XE2.NAME == "Author") // If {xe2.innertext = "Assembly"; // modify break; // can be used to find out.}} Break;}} xmldoc.save XML "); // Save.
/ / =================
The final result is:  XML Version = "1.0" Encoding = "GB2312"?>    Oberon's legacy  title>  Corets, EVA  author>  5.95  price>  book>   CS from getting started  title>  Ya Sheng  author>  58.3  price>  book>  bookstore> 3, delete  Node's GENRE attribute, Delete  node. XMLNodeList XNL = XmLDoc.selectsinglenode ("BookStore"). ChildNodes; Foreach (XMLNode XN IN XL) {XMLELEMENT XE = (XMLElement) xn;
IF (Xe.GetaTribute ("genre") == "fantasy") {xe.removeattribute ("genre"); // Delete the genre attribute} else if (Xe.GetaTRibute ("genre") == "Update Li Zan Hong") {Xe.removeall (); // Delete all the contents of the node}} Xmldoc.save ("BookStore.xml");
/ / ==================== The last result is:
转载请注明原文地址:https://www.9cbs.com/read-40548.html