Hello, I trying to serialize an object to use the result in other XML file. For example: I have the following XML File an inside the <Object/> element I want to insert the serialization's result.
<MyXML> <Data_1/> <Data_2/> <Object/> </MyXML> The problem is that when I serialize the object I obtain as result the following XML: <?xml version="1.0" encoding="utf-16"?> <Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <id>1</id> <firstName>Pablo</firstName> <lastName>Fernandez</lastName> </Root> Therefore, I should clean the result to put it inside the first XML file (I should take out the processing instruction and the namespaces). I know that the processing instructions is added by design as well as the namespaces, if I don't specify anyone. The question is, is there any way to avoid the processing instruction and the namespaces without using a clean function ? Below is the code that I am using. Thanks in advanced, Wilson Chiesa. Code: ----- using System; using System.Xml; using System.Xml.Serialization; using System.IO; class TestApp { static void Main(string[] args) { XmlSerializer oSer = new XmlSerializer(typeof(TestClass)); StringWriter sw = new StringWriter(); TestClass oTC = new TestClass(); oSer.Serialize(sw, oTC); Console.WriteLine("{0}", sw.ToString()); Console.ReadLine(); } } [System.Xml.Serialization.XmlRootAttribute("Root")] public class TestClass { public int id = 1; public string firstName = "Pablo"; public string lastName = "Fernandez"; } You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.