문제

I have to dialogue with a webservice whose response accepts a XElement object that represents a XML file. I have generated a XSD file from the XML and, via xsd.exe, I have generated a .cs class. What I want to know is: how I can convert the object from the .cs file into Xelement in order to provide it to the request? Is there a way to convert the XML to a XML object without declaring the nodes manually?

Best regards.

도움이 되었습니까?

해결책

For example If you have a class.cs You should use Serialization

   static void Main(string[] args)
   {
      clsPerson p=new clsPerson();
      p.FirstName = "Jeff";
      p.MI = "A";
      p.LastName = "Price";
      System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());
      x.Serialize(Console.Out, p);
      Console.WriteLine();
      Console.ReadLine();
   }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top