这个因为要做google团购导航的api,所以,这块代码供遇到相关问题的朋友参考。
View Code 1 string FilePath = @"\WROX\ADONET\Chapter07\Nwind\Data\"; 2 XDocument xdOrders = XDocument.Load(FilePath + "Orders.xml", 3 LoadOptions.PreserveWhitespace); 4 // Define the xmlns:xsi namespace and prefix 5 XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; 6 // Wrap the Order fragments with a root element 7 XDocument Orders = 8 new XDocument( 9 // Add an XML declaration 10 new XDeclaration("1.0", "utf-8", "yes"), 11 // Add a descriptive comment 12 new XComment("Created with LINQ to XML"), 13 // Start the root element 14 new XElement("Orders", 15 // Add the xmlns:xsi namespace and prefix 16 new XAttribute(XNamespace.Xmlns + "xsi", xsi), 17 // Add the noNamespaceSchemaLocation with xsi prefix 18 new XAttribute(xsi + "noNamespaceSchemaLocation", 19 FilePath + "Orders.xsd"), 20 // Add the created attribute with ISO8601 date 21 new XAttribute("generated", 22 DateTime.Now.ToUniversalTime().ToString("s")), 23 // Add the
个人小站 中国一线
最新评论