- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Introducing LINQ in Visual C#.NET
Introducing LINQ QR Code ISO/IEC18004 Printer In Visual C#.NET Using Barcode drawer for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in .NET framework applications. www.OnBarcode.comQuick Response Code Scanner In Visual C# Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.commore easily perform many of the XML-processing tasks that you have been performing with the traditional XML APIs from the System.Xml namespace. We will first examine why we need an XML API like LINQ to XML by comparing it to some alternatives. You ll then make your first steps with some code using LINQ to XML in an obligatory Hello World example. Matrix 2D Barcode Maker In C# Using Barcode maker for VS .NET Control to generate, create 2D image in .NET applications. www.OnBarcode.comPrint PDF-417 2d Barcode In C#.NET Using Barcode creation for .NET Control to generate, create PDF417 image in VS .NET applications. www.OnBarcode.comWhy we need LINQ to XML
Printing Barcode In C# Using Barcode creation for .NET Control to generate, create Barcode image in VS .NET applications. www.OnBarcode.comUSS Code 128 Creator In C#.NET Using Barcode generation for .NET framework Control to generate, create Code 128 Code Set A image in .NET applications. www.OnBarcode.comXML is ubiquitous nowadays, and is used extensively in applications written using general-purpose languages such as C# or VB.NET. It is used to exchange data between applications, store configuration information, persist temporary data, generate web pages or reports, and perform many other things. It is everywhere! Until now, XML hasn t been natively supported by most programming languages, which therefore required the use of APIs to deal with XML data. These APIs include XmlDocument, XmlReader, XPathNavigator, XslTransform for XSLT, and SAX and XQuery implementations. The problem is that these APIs are not well integrated with programming languages, often requiring several lines of unnecessarily convoluted code to achieve a simple result. You ll see an example of this in the next section (see listing 1.13). But for the moment, let s see what LINQ to XML has to offer. LINQ to XML extends the language-integrated query features offered by LINQ to add support for XML. It offers the expressive power of XPath and XQuery but in our programming language of choice and with type safety and IntelliSense. If you ve worked on XML documents with .NET, you probably used the XML DOM (Document Object Model) available through the System.Xml namespace. LINQ to XML leverages experience with the DOM to improve the developer toolset and avoid the limitations of the DOM. Table 1.2 compares the characteristics of LINQ to XML with those of the XML DOM. Data Matrix 2d Barcode Creator In C# Using Barcode drawer for .NET framework Control to generate, create ECC200 image in .NET framework applications. www.OnBarcode.comUSPS PLANET Barcode Generation In Visual C# Using Barcode generation for .NET Control to generate, create USPS PLANET Barcode image in .NET framework applications. www.OnBarcode.comTable 1.2 Comparing LINQ to XML with the XML DOM to show how LINQ to XML is a better value proposition LINQ to XML characteristic Element-centric Declarative model LINQ to XML code presents a layout close to the hierarchical structure of an XML document Language-integrated queries XML DOM characteristic Document-centric Imperative model No resemblance between code and document structure QR Code Generator In Visual Basic .NET Using Barcode drawer for .NET Control to generate, create QR Code image in .NET framework applications. www.OnBarcode.comDecoding Denso QR Bar Code In C#.NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comNo integrated queries
Generate Quick Response Code In None Using Barcode maker for Font Control to generate, create QR-Code image in Font applications. www.OnBarcode.comPrinting Code 39 Extended In None Using Barcode generation for Font Control to generate, create Code-39 image in Font applications. www.OnBarcode.comFirst steps with LINQ to XML: Querying XML documents
UPC-A Supplement 2 Generator In Java Using Barcode creator for Java Control to generate, create Universal Product Code version A image in Java applications. www.OnBarcode.comUSS-128 Creator In None Using Barcode drawer for Font Control to generate, create UCC - 12 image in Font applications. www.OnBarcode.comTable 1.2
Universal Product Code Version A Maker In Visual Studio .NET Using Barcode drawer for Reporting Service Control to generate, create UPC-A image in Reporting Service applications. www.OnBarcode.comDataMatrix Recognizer In None Using Barcode scanner for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comComparing LINQ to XML with the XML DOM to show how LINQ to XML is a better value proposition (continued) LINQ to XML characteristic XML DOM characteristic Basic things require a lot of code Encoding Barcode In Visual Studio .NET Using Barcode creator for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comMake Matrix Barcode In VS .NET Using Barcode creation for .NET Control to generate, create Matrix image in .NET applications. www.OnBarcode.comCreating elements and attributes can be done in one instruction; text nodes are just strings Simplified XML namespace support UPC A Generator In Objective-C Using Barcode maker for iPad Control to generate, create UPC-A image in iPad applications. www.OnBarcode.comQR Creation In Java Using Barcode printer for Java Control to generate, create QR Code 2d barcode image in Java applications. www.OnBarcode.comRequires dealing with prefixes and namespace managers Heavyweight and memory intensive Everything is loaded in memory Different ways to work with the various bits of XML documents Faster and smaller Streaming capabilities Symmetry in element and attribute APIs
Whereas the DOM is low-level and requires a lot of code to precisely formulate what we want to achieve, LINQ to XML provides a higher-level syntax that allows us to do simple things simply. LINQ to XML also enables an element-centric approach in comparison to the document-centric approach of the DOM. This means that we can easily work with XML fragments (elements and attributes) without having to create a complete XML document. Two classes that the .NET Framework offers are XmlReader and XmlWriter. These classes provide support for working on XML text in its raw form and are lower-level than LINQ to XML. LINQ to XML uses the XmlReader and XmlWriter classes underneath and is not a completely new XML API. One advantage of this is that it allows LINQ to XML to remain compatible with XmlReader and XmlWriter. LINQ to XML makes creating documents more direct, but it also makes it easier to query XML documents. Expressing queries against XML documents feels more natural than having to write of lot of code with several loop instructions. Also, being part of the LINQ family of technologies, it is a good choice when we need to join diverse data sources. With LINQ to XML, Microsoft is aiming at 80 percent of the use cases. These cases involve straightforward XML formats and common processing. For the other cases, developers will continue to use the other APIs. Also, although LINQ to XML takes inspiration from XSLT, XPath, and XQuery, these technologies have benefits of their own and are designed for specific use cases, and within those scopes LINQ to XML is in no way able to compete with them. LINQ to XML is not enough for some specific cases, but its compatibility with the other XML APIs allows us to use
|
|