views:

124

answers:

1

I have a web service which returns a string representing an Xml file. The string is properly formed xml. I need to create FileInfo object from the string so that I can deserialize it.

I don't have the file path or even if i do thats of no use as it is a disconnected server.

I can convert string to XmlDocument by -

XmlDocument doc = new XmlDocument();
doc.LoadXml(MyString);

How do I get FileInfo so that I can deserialize it? Please help.


Solution:

Thanks for your replies. I created XmlReader from the string returned by the service and used XmlSerializer.Deserialize to get the object I needed.

using (XmlReader tr = XmlReader.Create(new StringReader(mystring)))
{
  XmlSerializer serializer = new XmlSerializer(typeof(<T>), extraTypes);
  <T> serizalizedForm =  serializer.Deserialize(tr) as <T>;
}
A: 

you need a class that represents the structure of the xml to deserialize it into. using xsd.exe and an instance of the xml that is returned you can create this class ( /c switch) and then use xmlserializer to deserialize. Here is an example of a method that deserializes the xml.

Jason w
Jason, the linked helped me. Thanks.
Dave