{"id":32,"date":"2007-04-17T11:21:27","date_gmt":"2007-04-17T16:21:27","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=32"},"modified":"2013-08-13T09:47:17","modified_gmt":"2013-08-13T07:47:17","slug":"linq-to-xml","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/","title":{"rendered":"LINQ to XML"},"content":{"rendered":"<p>LINQ offers an API called LINQ to XML, formally known as XLinq, that provides support for working with XML. This API resides in the System.Xml.Linq namespace, and you need to add a reference to the assembly with the same name to be able to use it. If you installed the Orcas March CTP bits, the assembly can be found in folder C:\\Windows\\Microsoft.NET\\Framework\\v3.5.20209.<\/p>\n<p>In the namespace you can find classes such as <tt>XNode<\/tt>, <tt>XElement<\/tt>, <tt>XAttribute<\/tt>, <tt>XText<\/tt>, etc.<\/p>\n<p>XElement implements an XML element. It has several constructor.  The following snippet constructs an empty element called winner.<\/p>\n<pre class=\"csharp\" name=\"code\">\r\n   XElement root = new XElement(\"winner\");\r\n   Console.WriteLine(root.ToString());\r\n<\/pre>\n<p>The output is <\/p>\n<pre class=\"console\">\r\n&lt;winner\/&gt;\r\n<\/pre>\n<p>Overloaded constructor can take additional parameters. If we pass a string:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nXElement root = new XElement(\"winner\", \"Manchester Utd.\");\r\n<\/pre>\n<p>We get:<\/p>\n<pre class=\"console\">\r\n&lt;winner&gt;Manchester Utd.&lt;\/winner&gt;\r\n<\/pre>\n<p>We can also pass an <tt>XAttribute<\/tt><\/p>\n<pre class=\"csharp\" name=\"code\">\r\nXElement root = new XElement(\"winner\", \"Manchester Utd.\",\r\n                             new XAttribute(\"Year\", 1999));\r\n<\/pre>\n<p>Or<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nXElement root = new XElement(\"winner\", new XAttribute(\"Year\", 1999),\r\n                             \"Manchester Utd.\");\r\n<\/pre>\n<p>In this case the winner element will have an attribute called <i>Year<\/i> having the value <i>1999<\/i>, and the text of the element will be <i>Manchester Utd.<\/i>.<\/p>\n<pre class=\"console\">\r\n&lt;winner Year=\"1999\">Manchester Utd.&lt;\/winner>\r\n<\/pre>\n<p>We can nest the all these to make a hierarchy of xml elements:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nXElement root = new XElement(\"winners\",\r\n                              new XElement(\"winner\",\r\n                                   new XElement(\"Name\", \"Barcelona\"),\r\n                                   new XElement(\"Country\", \"Spania\"),\r\n                                   new XElement(\"Year\", 2006)\r\n                              ),\r\n                              new XElement(\"winner\",\r\n                                   new XElement(\"Name\", \"Liverpool\"),\r\n                                   new XElement(\"Country\", \"Anglia\"),\r\n                                   new XElement(\"Year\", 2005)\r\n                              )\r\n                );\r\n<\/pre>\n<p>Of course, the XML elements don&#8217;t have to be created like that. They can be dynamically created. One way is using methods like <tt>Add<\/tt>, <tt>AddFirst<\/tt>, <tt>RemoveNodes<\/tt>, etc., methods from the <tt>XContainer<\/tt> class.<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nIEnumerable&lt;Winner&gt; winners = UCL.GetWinners();\r\nXElement root = new XElement(\"winners\");\r\n\r\nforeach (Winner w in winners)\r\n{\r\n      root.Add(new XElement(\"winner\",\r\n                             new XElement(\"Name\", w.Name),\r\n                             new XElement(\"Country\", w.Country),\r\n                             new XElement(\"Year\", w.Year)));\r\n}\r\n<\/pre>\n<p>And we can write this to a file with:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nRoot.Save(\"winners.xml\");\r\n<\/pre>\n<p>However, LINQ to XML offers a better way to generate XML content.<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nIEnumerable&lt;Winner&gt; winners = UCL.GetWinners();\r\n\r\nXElement root = new XElement(\"winners\", \r\n                    from w in winners\r\n                    select new XElement(\"winner\",\r\n                                        new XElement(\"Name\", w.Name),\r\n                                        new XElement(\"Country\", w.Country),\r\n                                        new XElement(\"Year\", w.Year)));  \r\n<\/pre>\n<p>The result in this case is the same as above.<\/p>\n<p>XElements has several overloads for saving its content to a file:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\npublic void Save(string fileName);\r\npublic void Save(TextWriter textWriter);\r\npublic void Save(XmlWriter writer);\r\npublic void Save(string fileName, bool preserveWhitespace);\r\npublic void Save(TextWriter textWriter, bool preserveWhitespace);\r\n<\/pre>\n<p>On the other hand, <tt>XElement<\/tt> offers several overloaded static methods for loading content from XML files:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\npublic static XElement Load(string uri);\r\npublic static XElement Load(TextReader textReader);\r\npublic static XElement Load(XmlReader reader);\r\npublic static XElement Load(string uri, bool preserveWhitespace);\r\npublic static XElement Load(TextReader textReader, bool preserveWhitespace);\r\npublic static XElement Parse(string text);\r\npublic static XElement Parse(string text, bool preserveWhitespace);\r\n<\/pre>\n<p>The following code loads the content of the file winners.xml and prints it in the console.<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nXElement root = XElement.Load(\"winners.xml\");\r\nConsole.WriteLine(root.ToString());\r\n<\/pre>\n<p>Considering that we have in winners.xml the list of UEL winners, we can load the content of this XML file and create Winner objects:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nIEnumerable&lt;Winner&gt; winners =\r\n             from e in XElement.Load(\"winners.xml\").Elements(\"winner\")\r\n             select new Winner\r\n                    {\r\n                         Name = (string)e.Element(\"Name\"),\r\n                         Country = (string)e.Element(\"Country\"),\r\n                         Year = (int)e.Element(\"Year\")\r\n                    };\r\n\r\nforeach (Winner w in winners)\r\n{\r\n     Console.WriteLine(\"{0} {1}, {2}\", w.Year, w.Name, w.Country);\r\n}\r\n<\/pre>\n<p><tt>XElement.Load()<\/tt> creates an <tt>XElement<\/tt> containing all the elements in the file. <tt>Elements()<\/tt> returns only the children called <i>winner<\/i> (in our case all the children elements of the root). After that we project Winners created by accessing the children of element &#8220;winner&#8221; in the XML file. The output is<\/p>\n<pre class=\"console\">\r\n2006 Barcelona, Spania\r\n2005 Liverpool, Anglia\r\n2004 FC Porto, Portugalia\r\n2003 AC Milan, Italia\r\n2002 Real Madrid, Spania\r\n2001 Bayern Munchen, Germania\r\n2000 Real Madrid, Spania\r\n1999 Manchester Utd., Anglia\r\n1998 Real Madrid, Spania\r\n1997 Borussia Dortmund, Germania\r\n1996 Juventus, Italia\r\n1995 AFC Ajax, Olanda\r\n1994 AC Milan, Italia\r\n1993 Olympique de Marseille, Franta\r\n<\/pre>\n<p>Now suppose you want to project only the names of the winners. In this case we could write:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nvar winners =\r\n            from e in XElement.Load(\"winners.xml\").Elements(\"winner\")\r\n            select (string)e.Element(\"Name\");\r\n\r\nforeach (var w in winners)\r\n{\r\n     Console.WriteLine(\"{0}\", w);\r\n}\r\n<\/pre>\n<\/p>\n<p>The ouput of the program is:<\/p>\n<pre class=\"console\">\r\nBarcelona\r\nLiverpool\r\nFC Porto\r\nAC Milan\r\nReal Madrid\r\nBayern Munchen\r\nReal Madrid\r\nManchester Utd.\r\nReal Madrid\r\nBorussia Dortmund\r\nJuventus\r\nAFC Ajax\r\nAC Milan\r\nOlympique de Marseille\r\n<\/pre>\n<p>This output however lists a team multiple times. If we want to have these winners listed only once we could apply the Distinct operator on the result and select the winners only once:<\/p>\n<pre class=\"csharp\" name=\"code\">\r\nvar winners =\r\n         from e in XElement.Load(\"winners.xml\").Elements(\"winner\")\r\n         select (string)e.Element(\"Name\");\r\n\r\nvar winnersDistinct = Enumerable.Distinct(winners);\r\n\r\nforeach (var w in winnersDistinct)\r\n{\r\n    Console.WriteLine(\"{0}\", w);\r\n}\r\n<\/pre>\n<p>The new output would be<\/p>\n<pre class=\"console\">\r\nBarcelona\r\nLiverpool\r\nFC Porto\r\nAC Milan\r\nReal Madrid\r\nBayern Munchen\r\nManchester Utd.\r\nBorussia Dortmund\r\nJuventus\r\nAFC Ajax\r\nOlympique de Marseille\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>LINQ offers an API called LINQ to XML, formally known as XLinq, that provides support for working with XML. This API resides in the System.Xml.Linq namespace, and you need to add a reference to the assembly with the same name to be able to use it. If you installed the Orcas March CTP bits, the &#8230; <a title=\"LINQ to XML\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/\" aria-label=\"Read more about LINQ to XML\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[11,14],"tags":[451,328],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-csharp","category-linq","tag-c","tag-linq-2"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,linq\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"LINQ to XML\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2007-04-17T16:21:27+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2013-08-13T07:47:17+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"LINQ to XML\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#article\",\"name\":\"LINQ to XML\",\"headline\":\"LINQ to XML\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2007-04-17T11:21:27+02:00\",\"dateModified\":\"2013-08-13T09:47:17+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#webpage\"},\"articleSection\":\"C#, LINQ, C++, linq\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"position\":4,\"name\":\".NET\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"name\":\"C#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"position\":5,\"name\":\"C#\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#listItem\",\"name\":\"LINQ to XML\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#listItem\",\"position\":6,\"name\":\"LINQ to XML\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/csharp\\\/#listItem\",\"name\":\"C#\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/\",\"name\":\"LINQ to XML\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2007\\\/04\\\/17\\\/linq-to-xml\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2007-04-17T11:21:27+02:00\",\"dateModified\":\"2013-08-13T09:47:17+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"LINQ to XML","description":"","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/","robots":"max-image-preview:large","keywords":"c++,linq","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#article","name":"LINQ to XML","headline":"LINQ to XML","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2007-04-17T11:21:27+02:00","dateModified":"2013-08-13T09:47:17+02:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#webpage"},"articleSection":"C#, LINQ, C++, linq"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","position":4,"name":".NET","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","name":"C#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","position":5,"name":"C#","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#listItem","name":"LINQ to XML"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#listItem","position":6,"name":"LINQ to XML","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/#listItem","name":"C#"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/","name":"LINQ to XML","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2007-04-17T11:21:27+02:00","dateModified":"2013-08-13T09:47:17+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"LINQ to XML","og:url":"https:\/\/mariusbancila.ro\/blog\/2007\/04\/17\/linq-to-xml\/","article:published_time":"2007-04-17T16:21:27+00:00","article:modified_time":"2013-08-13T07:47:17+00:00","twitter:card":"summary","twitter:title":"LINQ to XML"},"aioseo_meta_data":{"post_id":"32","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:04:51","updated":"2025-12-12 07:09:06","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":1,"uagb_excerpt":"LINQ offers an API called LINQ to XML, formally known as XLinq, that provides support for working with XML. This API resides in the System.Xml.Linq namespace, and you need to add a reference to the assembly with the same name to be able to use it. If you installed the Orcas March CTP bits, the&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/csharp\/\" class=\"advgb-post-tax-term\">C#<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/linq\/\" class=\"advgb-post-tax-term\">LINQ<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C#<\/span>","<span class=\"advgb-post-tax-term\">LINQ<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/linq\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/linq\/\" class=\"advgb-post-tax-term\">linq<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">linq<\/span>"]}},"comment_count":"1","relative_dates":{"created":"Posted 19 years ago","modified":"Updated 13 years ago"},"absolute_dates":{"created":"Posted on April 17, 2007","modified":"Updated on August 13, 2013"},"absolute_dates_time":{"created":"Posted on April 17, 2007 11:21 am","modified":"Updated on August 13, 2013 9:47 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-w","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":2,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":1614,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions\/1614"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}