Filtering XML with LINQ to XML

Filtering an XML document with LINQ to XML is very easy.

<TRUCKS>
    <TRUCKCOUNT>3</TRUCKCOUNT>
    <TRUCK>
        <CARRIER>MERKIN TRANSPORTATION INC</CARRIER>
        <CARRIERPHONE>(919)258-0939</CARRIERPHONE>
        <UNITNO>509</UNITNO>
        <UNITTYPE>TRACTOR</UNITTYPE>
        <DIMS>
            <BOXLENGTH>0</BOXLENGTH>
            <BOXWIDTH>0</BOXWIDTH>
            <BOXHEIGHT>0</BOXHEIGHT>
        </DIMS>
        <SATELLITE>N</SATELLITE>
        <AVAILABLE>05/24/2012 07:30</AVAILABLE>
        <STATUS>In Service</STATUS>
        <ISCONFIRMED>Y</ISCONFIRMED>
        <TEAM>N</TEAM>
        <LOCATION>GAS CITY, IN</LOCATION>
    </TRUCK>
    <TRUCK>
        <CARRIER>NICKELL FLIGHT SCHOOLS</CARRIER>
        <CARRIERPHONE>(805)767-6700</CARRIERPHONE>
        <UNITNO>958</UNITNO>
        <UNITTYPE>VAN</UNITTYPE>
        <DIMS>
            <BOXLENGTH>144</BOXLENGTH>
            <BOXWIDTH>50</BOXWIDTH>
            <BOXHEIGHT>69</BOXHEIGHT>
        </DIMS>
        <SATELLITE>N</SATELLITE>
        <AVAILABLE>05/26/2012 07:00</AVAILABLE>
        <STATUS>On A Load</STATUS>
        <ISCONFIRMED>Y</ISCONFIRMED>
        <TEAM>N</TEAM>
        <LOCATION>GAS CITY, IN</LOCATION>
    </TRUCK>
    <TRUCK>
        <CARRIER>BEST BRAINS, INC</CARRIER>
        <CARRIERPHONE>(888)345-5655</CARRIERPHONE>
        <UNITNO>427</UNITNO>
        <UNITTYPE>MEDIUM STRAIGHT</UNITTYPE>
        <DIMS>
            <BOXLENGTH>276</BOXLENGTH>
            <BOXWIDTH>92</BOXWIDTH>
            <BOXHEIGHT>88</BOXHEIGHT>
        </DIMS>
        <SATELLITE>N</SATELLITE>
        <AVAILABLE>05/24/2012 09:00</AVAILABLE>
        <STATUS>In Service</STATUS>
        <ISCONFIRMED>Y</ISCONFIRMED>
        <TEAM>N</TEAM>
        <LOCATION>GAS CITY, IN</LOCATION>
    </TRUCK>
</TRUCKS>

Here is the C# to use LINQ to XML.

public void Main()
{   
    string fileName = @"C:\Contents\\Web\MyApp\App_Data\trucks.xml"; 
    string buffer = File.ReadAllText( fileName );
    XDocument xDoc = GetSortedTrucksXml( buffer );
    xDoc.Dump();
}

public XDocument GetSortedTrucksXml( string xmlBuffer )
{
    XDocument xdoc = XDocument.Parse( xmlBuffer );
    int Counter = 0;    
    var trucks = from s in xdoc.Element( "TRUCKS" ).Elements( "TRUCK" )
                 orderby (string)s.Element( "CARRIER" ), 
                         (string)s.Element( "UNITNO" ) 
                 select getNewTruckElement( s, Counter++ );

    var newDoc = new XDocument();
    newDoc.Add( new XElement( "TRUCKS", trucks ) );
    return newDoc;
}

private XElement getNewTruckElement( XElement s, int Counter ) {
    // Add as many elements from the TRUCK as needed 
    // here. 
    XElement result = new XElement( "TRUCK" ,
                          s.Element( "CARRIER" ), 
                          s.Element( "UNITNO" ),
                          s.Element( "UNITTYPE" ),
                          s.Element( "LOCATION" ),
                          s.Element( "DIMS" ) );

    result.SetAttributeValue( "Counter", Counter.ToString() );                  
    return result;
}