SlideShare a Scribd company logo
1 of 13
Monthly Features: Technical Showcase What is LINQ to XML? Microsoft says: “LINQ to XML provides an in-memory XML programming interface that leverages the .NET Language-Integrated Query (LINQ) Framework. LINQ to XML uses the latest .NET Framework language capabilities and is comparable to an updated, redesigned Document Object Model (DOM) XML programming interface.”
Monthly Features: Technical Showcase What is LINQ to XML? Alternative to using XPath Uses anonymous types to provide strongly typed access to XML elements and attributes. Not a replacement for XSLT
Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
Monthly Features: Technical Showcase Get PurchaseIds of orders greater than $40.00 Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseIds = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                   wherefloat.Parse(purchaseOrder.Attribute("Total").Value) > 40.00f                   selectpurchaseOrder.Attribute("Id").Value;   foreach (varpurchaseIdinpurchaseIds)   Console.WriteLine("PurchaseId: {0}", purchaseId); Order Ids Greater than $40.00 PurchaseId: 83123 PurchaseId: 83125
Monthly Features: Technical Showcase Add a reference to System.Xml.Linq. Classes XDocument– Class used to interact with an XML document XElement– Represents an element in an XML document XAttribute– Represents an attribute in an XML document XNamespace – Used to specify a namespace in an XML document  i.e.: /my:myFields/my:RepeatingTable LINQ to XML Classes
Monthly Features: Technical Showcase Methods and Properties XDocument.Root– Returns the root XElement of the XML document XContainer.Elements() – Returns an IEnumberable<XElement> of all matching elements  Example: myDocument.Root.Elements(“PurchaseOrders”); XContainer.Attributes() – Returns an IEnumerable<XAttribute> XContainer.Element() – Returns a single XElement Example: purchaseOrderElement.Element(“CustomerName”).Value; XContainer.Attribute() – Returns a single XAttribute .Any() Extension Method – Returns true if items exist in a IEnumerable<> .First() Extension Method – Returns first item in an IEnumberable<> LINQ to XML Methods and Properties
Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
Monthly Features: Technical Showcase Get Purchase Orders greater than $40.00 Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseOrders = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                      wherefloat.Parse(purchaseOrder.Attribute("Total").Value) > 40.00f                      selectnew                      {                        Id = purchaseOrder.Attribute("Id").Value,                        Total = float.Parse(purchaseOrder.Attribute("Total").Value),                        CustomerName = purchaseOrder.Element("CustomerName").Value,                        CustomerState = purchaseOrder.Element("CustomerState").Value                      };   foreach (varpurchaseOrderinpurchaseOrders)   Console.WriteLine("PurchaseId: {0}: {1} ({2}) - {3}",       purchaseOrder.Id,       purchaseOrder.CustomerName,       purchaseOrder.CustomerState,       purchaseOrder.Total); Returns Orders Greater than $40.00 PurchaseId: 83123: Joe Bob (TX) - 59.97 PurchaseId: 83125: John Smith (OK) - 49.98
Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
Monthly Features: Technical Showcase Get Purchase Orders with at least 2 items Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseOrders = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                      wherepurchaseOrder.Element("Items").Elements("Item").Count() >= 2                      selectnew                      {                          Id = purchaseOrder.Attribute("Id").Value,                          ItemCount = purchaseOrder.Element("Items").Elements("Item").Count()                      };   foreach (varpurchaseOrderinpurchaseOrders)     Console.WriteLine("PurchaseId: {0}: ItemCount: {1}",         purchaseOrder.Id,         purchaseOrder.ItemCount); Returns Orders With at least 2 items PurchaseId: 83123: ItemCount: 3 PurchaseId: 83125: ItemCount: 2
Monthly Features: Technical Showcase InfoPath <my:myFieldsxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-30T15:48:37"              xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"xml:lang="en-US">   <my:RepeatingTable>     <my:Item>       <my:Name>Polo Shirt</my:Name>       <my:Color>Red</my:Color>       <my:Price>19.99</my:Price>     </my:Item>     <my:Item>       <my:Name>Jeans</my:Name>       <my:Color>Blue</my:Color>       <my:Price>29.99</my:Price>     </my:Item>   </my:RepeatingTable>   <my:Id>83123</my:Id> </my:myFields>
Monthly Features: Technical Showcase Querying a repeating table in InfoPath Reference System.Linq (contained in System.Core) Reference System.Xml.Linq (contained in System.Xml.Linq) Returns // use the MainDataSource to read the XML of the InfoPath Form XDocumentinfoPathDocument = XDocument.Load(newSystem.IO.StringReader(MainDataSource.CreateNavigator().OuterXml));   // required to access my: namespace XNamespacemyNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-30T15:48:37";   // use descendants node to find any element with the name Item in the tree var items = from item ininfoPathDocument.Descendants(myNamespace + "Item")             selectnew             {                 Name = item.Element(myNamespace + "Name").Value,                 Color = item.Element(myNamespace + “Color").Value,                 Price = item.Element(myNamespace + "Price").Value             };   foreach (var item in items) {     // do something }
Monthly Features: Technical Showcase Questions? Code Samples available at www.dotnetmafia.com.

More Related Content

Similar to Introduction to LINQ To XML

Struts2
Struts2Struts2
Struts2yuvalb
 
Mark Logic StrangeLoop 2010
Mark Logic StrangeLoop 2010Mark Logic StrangeLoop 2010
Mark Logic StrangeLoop 2010Christopher Biow
 
Krazykoder struts2 ui_tags
Krazykoder struts2 ui_tagsKrazykoder struts2 ui_tags
Krazykoder struts2 ui_tagsKrazy Koder
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container Listguest53eac8
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskRichard Davis
 
crystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.comcrystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.comSigit Yunanto
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
NEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator PresentationNEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator Presentationaskankit
 
IBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for MobileIBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for MobileChris Toohey
 
Hyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptxHyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptxvanajaanbarasu
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 

Similar to Introduction to LINQ To XML (20)

Struts2
Struts2Struts2
Struts2
 
Relational data as_xml
Relational data as_xmlRelational data as_xml
Relational data as_xml
 
Mark Logic StrangeLoop 2010
Mark Logic StrangeLoop 2010Mark Logic StrangeLoop 2010
Mark Logic StrangeLoop 2010
 
Krazykoder struts2 ui_tags
Krazykoder struts2 ui_tagsKrazykoder struts2 ui_tags
Krazykoder struts2 ui_tags
 
HTML5 Fundamentals
HTML5 FundamentalsHTML5 Fundamentals
HTML5 Fundamentals
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Xml
XmlXml
Xml
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
 
crystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.comcrystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.com
 
Rendering The Fat
Rendering The FatRendering The Fat
Rendering The Fat
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
 
What is xml
What is xmlWhat is xml
What is xml
 
NEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator PresentationNEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator Presentation
 
Html5 Overview
Html5 OverviewHtml5 Overview
Html5 Overview
 
IBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for MobileIBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for Mobile
 
Hyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptxHyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptx
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 

More from Corey Roth

Introduction to Microsoft Teams and Office 365 Groups
Introduction to Microsoft Teams and Office 365 GroupsIntroduction to Microsoft Teams and Office 365 Groups
Introduction to Microsoft Teams and Office 365 GroupsCorey Roth
 
Compliance and eDiscovery with Office 365
Compliance and eDiscovery with Office 365 Compliance and eDiscovery with Office 365
Compliance and eDiscovery with Office 365 Corey Roth
 
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013Corey Roth
 
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...Corey Roth
 
Configuring SharePoint Search for an Optimal Document Management Experience
Configuring SharePoint Search for an Optimal Document Management ExperienceConfiguring SharePoint Search for an Optimal Document Management Experience
Configuring SharePoint Search for an Optimal Document Management ExperienceCorey Roth
 
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013Corey Roth
 
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...Corey Roth
 
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...Corey Roth
 
Office 365 - Introduction to SharePoint Online Development - Lync and Learn
Office 365 - Introduction to SharePoint Online Development - Lync and LearnOffice 365 - Introduction to SharePoint Online Development - Lync and Learn
Office 365 - Introduction to SharePoint Online Development - Lync and LearnCorey Roth
 
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...New SharePoint development features using Visual Studio 2012 - SharePoint Sat...
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...Corey Roth
 
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...Corey Roth
 
Making the Most of Search in SharePoint Online - TechEd North America
Making the Most of Search in SharePoint Online - TechEd North AmericaMaking the Most of Search in SharePoint Online - TechEd North America
Making the Most of Search in SharePoint Online - TechEd North AmericaCorey Roth
 
New SharePoint development features using Visual Studio 11 - San Antonio Shar...
New SharePoint development features using Visual Studio 11 - San Antonio Shar...New SharePoint development features using Visual Studio 11 - San Antonio Shar...
New SharePoint development features using Visual Studio 11 - San Antonio Shar...Corey Roth
 
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...Corey Roth
 
Extending SharePoint 2010 to your customers and partners
Extending SharePoint 2010 to your customers and partnersExtending SharePoint 2010 to your customers and partners
Extending SharePoint 2010 to your customers and partnersCorey Roth
 
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...Corey Roth
 
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011Instant ECM with SharePoint 2010 - SPTechCon Boston 2011
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011Corey Roth
 
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...Corey Roth
 
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest Group
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest GroupGetting the most ouf of SharePoint Search - Tulsa SharePoint Interest Group
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest GroupCorey Roth
 
Instant ECM with SharePoint 2010
Instant ECM with SharePoint 2010Instant ECM with SharePoint 2010
Instant ECM with SharePoint 2010Corey Roth
 

More from Corey Roth (20)

Introduction to Microsoft Teams and Office 365 Groups
Introduction to Microsoft Teams and Office 365 GroupsIntroduction to Microsoft Teams and Office 365 Groups
Introduction to Microsoft Teams and Office 365 Groups
 
Compliance and eDiscovery with Office 365
Compliance and eDiscovery with Office 365 Compliance and eDiscovery with Office 365
Compliance and eDiscovery with Office 365
 
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013
Surfacing Your External Data using BCS in SharePoint 2013 - Dev Connections 2013
 
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
Office 365 - Introduction to SharePoint Online Development - SharePoint Conne...
 
Configuring SharePoint Search for an Optimal Document Management Experience
Configuring SharePoint Search for an Optimal Document Management ExperienceConfiguring SharePoint Search for an Optimal Document Management Experience
Configuring SharePoint Search for an Optimal Document Management Experience
 
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
 
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...
Publishing SharePoint 2013 Apps to the Office Store - Austin SharePoint Users...
 
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...
What you need to know about Search in SharePoint 2013 Preview - DFW SharePoin...
 
Office 365 - Introduction to SharePoint Online Development - Lync and Learn
Office 365 - Introduction to SharePoint Online Development - Lync and LearnOffice 365 - Introduction to SharePoint Online Development - Lync and Learn
Office 365 - Introduction to SharePoint Online Development - Lync and Learn
 
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...New SharePoint development features using Visual Studio 2012 - SharePoint Sat...
New SharePoint development features using Visual Studio 2012 - SharePoint Sat...
 
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...
Pitching Office 365 to your Energy Customers - Microsoft Worldwide Partner Co...
 
Making the Most of Search in SharePoint Online - TechEd North America
Making the Most of Search in SharePoint Online - TechEd North AmericaMaking the Most of Search in SharePoint Online - TechEd North America
Making the Most of Search in SharePoint Online - TechEd North America
 
New SharePoint development features using Visual Studio 11 - San Antonio Shar...
New SharePoint development features using Visual Studio 11 - San Antonio Shar...New SharePoint development features using Visual Studio 11 - San Antonio Shar...
New SharePoint development features using Visual Studio 11 - San Antonio Shar...
 
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...
Office 365 - Introduction to SharePoint Online Development - SharePoint Satur...
 
Extending SharePoint 2010 to your customers and partners
Extending SharePoint 2010 to your customers and partnersExtending SharePoint 2010 to your customers and partners
Extending SharePoint 2010 to your customers and partners
 
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...
Advanced BCS - Business Data Connectivity Models and Custom Connectors - SPTe...
 
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011Instant ECM with SharePoint 2010 - SPTechCon Boston 2011
Instant ECM with SharePoint 2010 - SPTechCon Boston 2011
 
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...
SharePoint 2010 Development for ASP.NET Developers - SharePoint Saturday Hous...
 
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest Group
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest GroupGetting the most ouf of SharePoint Search - Tulsa SharePoint Interest Group
Getting the most ouf of SharePoint Search - Tulsa SharePoint Interest Group
 
Instant ECM with SharePoint 2010
Instant ECM with SharePoint 2010Instant ECM with SharePoint 2010
Instant ECM with SharePoint 2010
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Introduction to LINQ To XML

  • 1. Monthly Features: Technical Showcase What is LINQ to XML? Microsoft says: “LINQ to XML provides an in-memory XML programming interface that leverages the .NET Language-Integrated Query (LINQ) Framework. LINQ to XML uses the latest .NET Framework language capabilities and is comparable to an updated, redesigned Document Object Model (DOM) XML programming interface.”
  • 2. Monthly Features: Technical Showcase What is LINQ to XML? Alternative to using XPath Uses anonymous types to provide strongly typed access to XML elements and attributes. Not a replacement for XSLT
  • 3. Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
  • 4. Monthly Features: Technical Showcase Get PurchaseIds of orders greater than $40.00 Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseIds = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                   wherefloat.Parse(purchaseOrder.Attribute("Total").Value) > 40.00f                   selectpurchaseOrder.Attribute("Id").Value;   foreach (varpurchaseIdinpurchaseIds)   Console.WriteLine("PurchaseId: {0}", purchaseId); Order Ids Greater than $40.00 PurchaseId: 83123 PurchaseId: 83125
  • 5. Monthly Features: Technical Showcase Add a reference to System.Xml.Linq. Classes XDocument– Class used to interact with an XML document XElement– Represents an element in an XML document XAttribute– Represents an attribute in an XML document XNamespace – Used to specify a namespace in an XML document i.e.: /my:myFields/my:RepeatingTable LINQ to XML Classes
  • 6. Monthly Features: Technical Showcase Methods and Properties XDocument.Root– Returns the root XElement of the XML document XContainer.Elements() – Returns an IEnumberable<XElement> of all matching elements Example: myDocument.Root.Elements(“PurchaseOrders”); XContainer.Attributes() – Returns an IEnumerable<XAttribute> XContainer.Element() – Returns a single XElement Example: purchaseOrderElement.Element(“CustomerName”).Value; XContainer.Attribute() – Returns a single XAttribute .Any() Extension Method – Returns true if items exist in a IEnumerable<> .First() Extension Method – Returns first item in an IEnumberable<> LINQ to XML Methods and Properties
  • 7. Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
  • 8. Monthly Features: Technical Showcase Get Purchase Orders greater than $40.00 Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseOrders = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                      wherefloat.Parse(purchaseOrder.Attribute("Total").Value) > 40.00f                      selectnew                      {                        Id = purchaseOrder.Attribute("Id").Value,                        Total = float.Parse(purchaseOrder.Attribute("Total").Value),                        CustomerName = purchaseOrder.Element("CustomerName").Value,                        CustomerState = purchaseOrder.Element("CustomerState").Value                      };   foreach (varpurchaseOrderinpurchaseOrders)   Console.WriteLine("PurchaseId: {0}: {1} ({2}) - {3}",       purchaseOrder.Id,       purchaseOrder.CustomerName,       purchaseOrder.CustomerState,       purchaseOrder.Total); Returns Orders Greater than $40.00 PurchaseId: 83123: Joe Bob (TX) - 59.97 PurchaseId: 83125: John Smith (OK) - 49.98
  • 9. Monthly Features: Technical Showcase Sample XML File <?xmlversion="1.0"encoding="utf-8" ?> <PurchaseOrders>   <PurchaseOrderId="83123"Total="59.97">     <CustomerName>Joe Bob</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="32324"Name="T-Shirt"Color="White"Price="9.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83124"Total="19.99">     <CustomerName>Bob Joe</CustomerName>     <CustomerState>TX</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Red"Price="19.99" />     </Items>   </PurchaseOrder>   <PurchaseOrderId="83125"Total="49.98">     <CustomerName>John Smith</CustomerName>     <CustomerState>OK</CustomerState>     <Items>       <ItemId="26134"Name="Polo Shirt"Color="Blue"Price="19.99" />       <ItemId="01283"Name="Jeans"Color="Blue"Price="29.99" />     </Items>   </PurchaseOrder> </PurchaseOrders>
  • 10. Monthly Features: Technical Showcase Get Purchase Orders with at least 2 items Returns XDocumentpurchaseOrderXml = XDocument.Load("PurchaseOrder.xml");   varpurchaseOrders = frompurchaseOrderinpurchaseOrderXml.Root.Elements("PurchaseOrder")                      wherepurchaseOrder.Element("Items").Elements("Item").Count() >= 2                      selectnew                      {                          Id = purchaseOrder.Attribute("Id").Value,                          ItemCount = purchaseOrder.Element("Items").Elements("Item").Count()                      };   foreach (varpurchaseOrderinpurchaseOrders)     Console.WriteLine("PurchaseId: {0}: ItemCount: {1}",         purchaseOrder.Id,         purchaseOrder.ItemCount); Returns Orders With at least 2 items PurchaseId: 83123: ItemCount: 3 PurchaseId: 83125: ItemCount: 2
  • 11. Monthly Features: Technical Showcase InfoPath <my:myFieldsxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-30T15:48:37"              xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"xml:lang="en-US">   <my:RepeatingTable>     <my:Item>       <my:Name>Polo Shirt</my:Name>       <my:Color>Red</my:Color>       <my:Price>19.99</my:Price>     </my:Item>     <my:Item>       <my:Name>Jeans</my:Name>       <my:Color>Blue</my:Color>       <my:Price>29.99</my:Price>     </my:Item>   </my:RepeatingTable>   <my:Id>83123</my:Id> </my:myFields>
  • 12. Monthly Features: Technical Showcase Querying a repeating table in InfoPath Reference System.Linq (contained in System.Core) Reference System.Xml.Linq (contained in System.Xml.Linq) Returns // use the MainDataSource to read the XML of the InfoPath Form XDocumentinfoPathDocument = XDocument.Load(newSystem.IO.StringReader(MainDataSource.CreateNavigator().OuterXml));   // required to access my: namespace XNamespacemyNamespace = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-12-30T15:48:37";   // use descendants node to find any element with the name Item in the tree var items = from item ininfoPathDocument.Descendants(myNamespace + "Item")             selectnew             {                 Name = item.Element(myNamespace + "Name").Value,                 Color = item.Element(myNamespace + “Color").Value,                 Price = item.Element(myNamespace + "Price").Value             };   foreach (var item in items) {     // do something }
  • 13. Monthly Features: Technical Showcase Questions? Code Samples available at www.dotnetmafia.com.

Editor's Notes

  1. Talk about demo of purchase orders over $40.00
  2. Talk about the anonymous type we will be creating.
  3. Item Count
  4. Item Count