XObject and Annotations

XObject represents the base class of the whole LINQ to XML API, and it mainly provides methods and properties to work with annotations on nodes. Annotations are a new mechanism that maps metadata to XML nodes. For instance, we can add custom user information to our
nodes

Annotations applied to an XElement instance

XElement customer = XElement.Load(@"..\..\customer.xml");
CustomerAnnotation annotation = new CustomerAnnotation();
annotation.Notes = "This is a good customer!";
customer.AddAnnotation(annotation);

CustomerAnnotation is a custom type and can be any .NET type. We can then retrieve annotationsfrom XML nodes by using one of the two generic methods, Annotation and Annotations.These generic methods search for an annotation of type T or one that is derived from T in the current node, and if one exists, Annotation and Annotations return the first one or the full set of them, respectively.

annotation = customer.Annotation();

Because XObject is the base class of every kind of X* class that is used to describe an XML
node, annotations can be added to any node. Usually, annotations are used to keep state
information, such as the mapping to source entities or documents used to build XML, while
the code handles real XML content.

XNode Selection Methods

The XNode class provides some methods that are useful for selecting elements and nodes
related to the current node itself. For instance, the ElementsBeforeSelf and ElementsAfterSelf
methods both return a sequence of type IEnumerable that contains the elements
before or after the current node, respectively. They both provide an overload with a parameter
of type XName to filter elements by name.


In addition, NodesBeforeSelf and NodesAfterSelf methods return a sequence of type
IEnumerable that contains all the nodes, regardless of their node type, before or after
the current one.

Similarities Between XPath Axes and Extension Methods

Extension methods are defined in the System.Xml.Linq.Extensions class that recall XPath Axes
functions. The first two methods that we will consider are Ancestors and Descendants, which
return an IEnumerable sequence of elements for a particular XNode instance.
Descendants returns all the elements after the current node in the document graph, regardless
of their depth in the graph. Ancestors is somehow complementary to Descendants and returns
all the elements before the current node in the document graph. Both are shown here:


public static IEnumerable Ancestors(
this IEnumerable source)
where T: XNode;
public static IEnumerable Ancestors(
this IEnumerable source, XName name)
where T: XNode;
public static IEnumerable Descendants(
this IEnumerable source)
where T: XContainer;
public static IEnumerable Descendants(
this IEnumerable source, XName name)
where T: XContainer;

These methods are useful for querying an XML source to find a particular element after or
before the current one, regardless of its position in the graph

A LINQ query over XML, based on an XSD typed approach

Support for XSD and Validation of Typed Nodes

var ordersWithCustomersFromXml =
from c in xmlCustomers.customerCollection
join o in orders
on c.Name equals o.Name
orderby c.Name
select new {
Name = c.Name,
City = c.City,
IdProduct = o.IdProduct,
Quantity = o.Quantity };

Dialup Interfaces: PPP

When you dial your modem to an ISP, and it connects to their modem, the kernel doesn't just shove IP packets through it. There is a protocol called `Point-to-Point Protocol', or `PPP', which is used to negotiate with the other end before any packets are allowed through. This is used by the ISP to identify who is dialed up: on your Linux box, a program called the `PPP daemon' handles your end of the negotiation.

Because there are so many dialup users in the world, they usually don't have their own IP address: most ISPs will assign you one of theirs temporarily when you dial up (the PPP daemon will negotiate this). This is often called a `dynamic IP address', as separate from a `static IP address' which is the normal case where you have your own address permanently. Usually they are assigned by modem: the next time you dial up,you will probably get a different modem in the modem pool, and hence a different IP address.