c# qr codes Ancestors in Visual C#

Generator QR Code 2d barcode in Visual C# Ancestors

10.1.5 Ancestors
Generate QR Code ISO/IEC18004 In Visual C#
Using Barcode generation for VS .NET Control to generate, create QR Code image in Visual Studio .NET applications.
www.OnBarcode.com
Scan QR Code 2d Barcode In C#.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
The Ancestors axis method works exactly like the Descendants method, except instead of searching down the XML tree, it searches up the tree. It offers the same signature and has the same related methods, AncestorsAndSelf and AncestorNodes. Unlike all the other axis methods we ve discussed so far, Ancestors searches for matching elements that are above the current node within the XML tree. So far, we ve learned how to get a list of books within a category element using a combination of Element and Elements, as well as how to get every book within our XML using Descendants. In this section, we re going to learn how we can use Ancestors to get the list of categories that a given book is in. Since the category elements are nested, we ll look to get the full category path for a book in the following form:
Painting Data Matrix ECC200 In C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create Data Matrix ECC200 image in .NET applications.
www.OnBarcode.com
Barcode Creator In C#
Using Barcode drawer for .NET framework Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
LINQ to XML axis methods
Make Barcode In C#
Using Barcode generation for .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
QR Code 2d Barcode Creation In Visual C#
Using Barcode drawer for .NET framework Control to generate, create QR image in .NET applications.
www.OnBarcode.com
Domain Driven Design is in the: Technical/Design category.
Draw Code 128A In C#.NET
Using Barcode creation for .NET framework Control to generate, create Code 128B image in .NET applications.
www.OnBarcode.com
Making Universal Product Code Version E In Visual C#.NET
Using Barcode generator for .NET framework Control to generate, create GS1 - 12 image in .NET framework applications.
www.OnBarcode.com
The first thing we ll need to do is select the book that we re interested in. To do this, we can use the Descendants axis method to select all the books in our XML. Once we have all the books, we can filter the list of books down to the single one we re interested in using the Where and First standard query operators, like so:
Encode Denso QR Bar Code In Objective-C
Using Barcode generation for iPhone Control to generate, create QR Code JIS X 0510 image in iPhone applications.
www.OnBarcode.com
Quick Response Code Decoder In Visual C#
Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
XElement root = XElement.Load("categorizedBooks.xml"); XElement dddBook = root.Descendants("book") .Where(book => (string)book == "Domain Driven Design") .First();
EAN13 Scanner In Visual Studio .NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Barcode Scanner In VB.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
In the code, we select the Domain Driven Design book element. Once we have the book element in hand, we can call the Ancestors axis method to select all the parent categories for the book element. Once we have the list of parent elements, we ll do some special processing with Reverse and String.Join to get the categories formatted as we desire. When all is said and done, we end up with listing 10.8.
Encode UCC - 12 In None
Using Barcode drawer for Font Control to generate, create GS1 128 image in Font applications.
www.OnBarcode.com
PDF417 Reader In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Listing 10.8 Using Ancestors to query an XML document for elements above a particular element
Linear Barcode Generator In Visual Studio .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Linear 1D Barcode image in VS .NET applications.
www.OnBarcode.com
Recognize QR-Code In C#.NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
XElement root = XElement.Load("categorizedBooks.xml"); XElement dddBook = root.Descendants("book") .Where(book => (string)book == "Domain Driven Design" ).First(); IEnumerable<XElement> ancestors = dddBook.Ancestors("category").Reverse(); string categoryPath = Build the category path String.Join("/", ancestors.Select(e => (string)e.Attribute("name")).ToArray());
Create Code 128B In None
Using Barcode printer for Software Control to generate, create Code 128 Code Set B image in Software applications.
www.OnBarcode.com
Printing PDF-417 2d Barcode In None
Using Barcode printer for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Reverse the order, since we want the topmost category first
Printing 2D Barcode In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create 2D image in ASP.NET applications.
www.OnBarcode.com
Barcode Maker In Objective-C
Using Barcode maker for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Console.WriteLine((string)dddBook + " is in the: " + categoryPath + " category.");
The result printed to the console includes everything we expect:
Domain Driven Design is in the: Design/Technical category.
The final set of axis methods available within the LINQ to XML API allow you to retrieve all the elements or content that occur before or after the current element. Let s look at them next.
Query and transform XML with LINQ to XML
10.1.6 ElementsAfterSelf, NodesAfterSelf, ElementsBeforeSelf, and NodesBeforeSelf
The ElementsAfterSelf, ElementsBeforeSelf, NodesAfterSelf, and NodesBeforeSelf methods provide an easy way for us to retrieve all the elements or content that exist before or after the current element. As is evident from their names, the ElementsBeforeSelf and ElementsAfterSelf axis methods return all the XElement objects that occur before or after the current element in the XML tree, respectively. If you need to retrieve all nodes, and not just the elements, then the NodesBeforeSelf and NodesAfterSelf methods are what you re after. Let s return to our previous example to see how the ElementsBeforeSelf and ElementsAfterSelf axis methods work. Once again we ll be working with the XML shown in Listing 10.1. When we examined the Ancestors axis method, we looked at how we could retrieve the category path for a book within the XML tree. With the ElementsBeforeSelf and ElementsAfterSelf methods, we can look at the book elements that sit before or after the Domain Driven Design book element. It s important to note that unlike the Ancestors and Descendants axis methods, the ElementsBeforeSelf, ElementsAfterSelf, NodesBeforeSelf, and NodesAfterSelf methods only look at the elements and nodes at the same level as the current element. In listing 10.9, we ll use the ElementsBeforeSelf axis method to retrieve all the elements that are before the Domain Driven Design book element.
Copyright © OnBarcode.com . All rights reserved.