linq使用,asp.net 使用linq to xml中加xsi:noNamespaceSchemaLocation属性

今天在做linq to xml时,遇到了这么一个问题,给xml里面添加xsi:noNamespaceSchemaLocation.
这个因为要做google团购导航的api,所以,这块代码供遇到相关问题的朋友参考。
asp.net 使用linq to xml中加xsi:noNamespaceSchemaLocation属性linq使用asp.net 使用linq to xml中加xsi:noNamespaceSchemaLocation属性linq使用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 elements for U.S. customers 24 from o in xdOrders.Descendants("Order") 25 where o.Element("ShipCountry").Value == "USA" 26 orderby o.Element("OrderID").Value descending 27 select o)); 28 Orders.Save("Orders.xml"); 29 Process.Start("Orders.xml"); // Display the document in IE

个人小站 中国一线
Tags:  linq使用

延伸阅读

最新评论

发表评论