开发者

Convert XmlDocument to FileInfo

开发者 https://www.devze.com 2022-12-19 11:16 出处:网络
I have a web service which returns a string representing an Xml file. The string is properly formed xml.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消