advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the sample code for this article.
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
Email this articleEmail this article
 
XLinq Part 1: Classes and Methods
XLinq, one of a set of extensions to .NET languages, improves on the XML DOM in both flexibility and expressive power. This article series shows you how to take advantage of XLinq in your own applications. 

advertisement
early every .NET application needs to handle data that may reside in a wide range of data sources, from relational databases, to XML, to in-memory or disk-persisted objects. Although .NET Framework 2.0 exposes a number of classes to handle these types of data, it lacks a unified approach to handling data from disparate data sources. In other words, until now, you needed to learn a multitude of technologies such as ADO.NET, SQL, XML DOM, XML serialization, etc., to be able to read and update these various data sources. To solve this problem, Microsoft has released a set of technologies called Language-integrated Query (LINQ) that is specifically geared towards making data access consistent—regardless of the back-end data store.


Key Components of LINQ
At this early stage, the LINQ family consists of three technologies, although Microsoft or third-party developers may add more in the future:

  • LINQ is a general purpose API that provides the core foundation for a consistent query experience.
  • DLinq (also known as LINQ to SQL) is a LINQ extension geared mainly towards relational databases.
  • XLinq (also known as LINQ to XML) is a LINQ extension for querying XML documents, as well as creating or transforming XML.
This article focuses primarily on XLinq, which provides an in-memory XML programming API for handling and processing XML data.

What You Need
Visual Studio 2005 Professional RTM and the LINQ May 2006 Community Technology Preview.

XLinq takes advantage of the standard query operators (where, select, order by, group by) supplied by LINQ and adds query extensions specific to XML. XLinq combines the query and transformation power of XQuery and XPath with the .NET Framework to provide a consistent query experience. Compared to the XML DOM (the traditional method of querying XML documents), the XLinq is a newly designed, lightweight API that provides significant improvements.

 
Figure 1. XLinq Class Hierarchy: The figure shows the classes and relationships in the System.Xml.XLinq namespace.
XLinq Class Hierarchy
You'll find the XLinq-related classes in the System.Xml.XLinq namespace as shown in Figure 1.

Of the classes shown in Figure 1, the XNode and XContainer classes (shown in different color) are abstract. The XNode class is the base for element nodes, and provides a Parent method and methods such as AddBeforeThis, AddAfterThis, and Remove for updates in the imperative style. For IO, it provides methods for reading (ReadFrom) and writing (WriteTo).

Although the XElement class is bottom-most in the class hierarchy, it is the fundamental class. As the name suggests, it represents an XML element and allows you to perform the following operations:

  • Create elements with a specified element name
  • Change the element's contents
  • Add, change, or delete child elements
  • Add attributes to the element
  • Save the element as an XML fragment
  • Extract the contents in text form
Compared to the XML DOM, XLinq is much more flexible because it does not require you to always have a document object to be able to work with XML. Therefore, you can work directly with nodes and modify them as content of the document without having to start from a root XmlDocument object. This is a very powerful and flexible feature that you can use to compose larger trees and XML documents from tree fragments. Now that you have an overview of the XLinq's capabilities, the next few sections will examine the reading and writing features of XLinq before discussing the query capabilities.

  Next Page: Creating an XML Tree


Page 1: IntroductionPage 3: Querying XML
Page 2: Creating an XML TreePage 4: Deleting XML
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: BitLocker Encryption on Windows Server 2008
Go Parallel Article: Intel Thread Checker, Meet 20 Million LOC
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES