"Geoff" <ge*********@gmail.com> wrote in message news:db**************************@posting.google.c om...
Is it possible to pull a single node (element) out of a complex XML
file, using SelectSingleNode(), and then deserialize that node to an
object?
Yes, if your XML document looks like this, for example,
<MyDocument>
<ComplexInfo>
<DontCare SomeStatistic="55" />
</ComplexInfo>
<MyObject>
<Name>Geoff</Name>
</MyObject>
</MyDocument>
and you have a class to deserialize that looks like this,
public class MyObject
{
public string Name;
}
then you should have no problem selecting a single node, MyObject,
from the more complex document and then wrapping that node in an
XmlNodeReader to use for deserialization, like this,
XmlSerializer serializer = new XmlSerializer( typeof( MyObject));
XmlDocument doc = new XmlDocument( );
doc.Load( "myDocument.xml");
XmlNode node = doc.SelectSingleNode( "//MyObject");
MyObject obj = serializer.Deserialize( new XmlNodeReader( node)) as MyObject;
Derek Harmon