I use AutoMapper on almost any project where I don't want to write boring and repetitive code to map one object to another. I realized that AutoMapper works well not only with strongly typed objects but with XML as well.

I needed a way to map XML to Entity Framework DTOs. For example,

<Target Name="Inbound.dll">  
    <Modules>
        <Module Name="WebServices.Inbound.dll" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0">
            <Metrics>
                <Metric Name="MaintainabilityIndex" Value="94" />
                <Metric Name="CyclomaticComplexity" Value="112" />
            </Metrics>
        </Module>
    </Modules>
</Target>  

should be mapped into

  
  
public class Target  
{
    public int TargetId { get; set; }
    public string Name { get; set; }        
    public virtual List Modules { get; set;}
}       
public class Module  
{
    public int ModuleId { get; set; }
    public string Name { get; set; }
    public string AssemblyVersion { get; set; }
    public string FileVersion { get; set; }
    public int TargetId { get; set; }        
    public virtual Metrics Metrics { get; set; }
    public int MetricsId { get; set; }
}
  

This is how mapping can be done:

  
  
AutoMapperConfig.CreateMaps();

var targets = new List();  
foreach (var targetElement in elements.Descendants("Target"))  
{                
    var target = Mapper.Map(targetElement);
    targets.Add(target);

    foreach (var moduleElement in targetElement.Descendants("Module"))
    {             
        var module = Mapper.Map(moduleElement);  
        target.Modules.Add(module);
    }
}
public static void CreateMaps()  
{            
    Mapper.CreateMap()
        .ForMember(m => m.Name, opt => opt.MapFrom(src => GetStringAttribute(src, "Name")));

    Mapper.CreateMap()
    {
        .ForMember(m => m.Name, opt => opt.MapFrom(src => GetStringAttribute(src, "Name")))
        .ForMember(m => m.FileVersion, opt => opt.MapFrom(src => GetStringAttribute(src, "FileVersion")))
        .ForMember(m => m.AssemblyVersion, opt => opt.MapFrom(src => GetStringAttribute(src, "AssemblyVersion")))
    }
}
private static string GetStringAttribute(XElement element, string name)  
{
    return element.Attribute(name) != null ? element.Attribute(name).Value : string.Empty;
}
  

See full source for more details.