XML 操作

前端之家收集整理的这篇文章主要介绍了XML 操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
View Code 
 string FilePath = @"\WROX\ADONET\Chapter07\Nwind\Data\";  
 XDocument xdOrders = XDocument.Load(FilePath + "Orders.xml",LoadOptions.PreserveWhitespace);  
  // Define the xmlns:xsi namespace and prefix  
  XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";  
  // Wrap the Order fragments with a root element  
  XDocument Orders =  
  new XDocument(  
  // Add an XML declaration  
 new XDeclaration("1.0","utf-8","yes"),// Add a descriptive comment  
 new XComment("Created with LINQ to XML"),// Start the root element  
 new XElement("Orders",// Add the xmlns:xsi namespace and prefix  
 new XAttribute(XNamespace.Xmlns + "xsi",xsi),// Add the noNamespaceSchemaLocation with xsi prefix  
 new XAttribute(xsi + "noNamespaceSchemaLocation",FilePath + "Orders.xsd"),// Add the created attribute with ISO8601 date  
 new XAttribute("generated",DateTime.Now.ToUniversalTime().ToString("s")),// Add the <Order> elements for U.S. customers  
 from o in xdOrders.Descendants("Order")  
 where o.Element("ShipCountry").Value == "USA"  
 orderby o.Element("OrderID").Value descending  
 select o));  
 Orders.Save("Orders.xml");  
 Process.Start("Orders.xml"); // Display the document in IE

猜你在找的XML相关文章