0

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.

lugeno
  • 1,055
  • 3
  • 10
  • 18

1 Answers1

1

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();
   }
  • In which line do you convert the p object into a XElement object? – lugeno Jul 09 '13 at 09:31
  • You can loop on list and convert to list –  Jul 09 '13 at 09:31
  • Suppose there is another filed "Address". If I do not specify p.Address the serialized XML does not show the entire tag
    . Is there a way to show the Address tag blank if not specified?
    – lugeno Jul 09 '13 at 10:09