Convert XmlDocument to FileInfo
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 XmlSeria开发者_如何学JAVAlizer(typeof(<T>), extraTypes);
<T> serizalizedForm = serializer.Deserialize(tr) as <T>;
}
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 (Update: This link is broken)
精彩评论