I want to serialize an XDocument
object. I wrote this code.
XDocument signup_xml_file = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("signup_xml_file"),
new XElement("Student",
new XElement("univ_id", univ_id),
new XElement("personal_id",personal_id),
new XElement("user_name", user_name)));
client.Connect(host_name, port);
//connect to the server .
bf.Serialize(client.GetStream(), signup_xml_file); // serialize the signup_xml_file
I get the following exception when attempting to serialize the XDocument
. Is there any way to make the XDocument
class Serializable, or is there another way to send my XDocument
?
Type 'System.Xml.Linq.XDocument' in Assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
XDocuments are not intended to be serialized. In a way they are serializers themselves.
But you can simply write them: signup_xml_file.Save(client.GetStream());
which also eliminates serializer overhead.
Edit:
And on the other side you will need
var doc = XDocument.Load(someStream);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With