XML 操作
发布时间:2020-12-15 23:43:46 所属栏目:百科 来源:网络整理
导读:View Code string FilePath = @"WROXADONETChapter07NwindData"; XDocument xdOrders = XDocument.Load(FilePath + "Orders.xml",LoadOptions.PreserveWhitespace); // Define the xmlns:xsi namespace and prefix XNamespace xsi = "http://www.w3.or
View Code string FilePath = @"WROXADONETChapter07NwindData"; 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |