Transforming serialized .net object with XSLT
-
Tuesday, November 13, 2012 6:54 AM
I have a big .net class and a few xslt files. I'm serializing my object to transform with my xslt files.
My class' name is Application and it has an Applicant property which contains a collection of applications.
public class Application { public Person Applicant { get; set; } } public class Person { public List<Application> Applications { get; set; } }When I serialize an instance of my class, normally the Xml that I obtained contains z:Ref="i18" attributes to prevent infinite Xml creation to describe existing referenced properties. But this situation changes the required Xpath expressions that I have to write in my Xslt file.
Do I have a chance to serialize my object containing the real entity values instead of z:Ref tags for a specified depth?
Here is my serialization code:
public string Serialize(object input) { XmlDocument XmlDoc = new XmlDocument(); DataContractSerializer xmlDataContractSerializer = new DataContractSerializer(input.GetType()); MemoryStream MemStream = new MemoryStream(); try { xmlDataContractSerializer.WriteObject(MemStream, input); MemStream.Position = 0; XmlDoc.Load(MemStream); return XmlDoc.InnerXml; } finally { MemStream.Close(); } }Thanks in advance,
All Replies
-
Tuesday, November 13, 2012 9:37 AM
When using this method:
public static string SerializeToString(object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, obj);
return writer.ToString();
}
}I get an error if I make an infinitive loop. Otherwise I get this XML:
<?xml version="1.0" encoding="utf-16" ?>
<Application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Applicant>
<Applications>
<Application />
</Applications>
</Applicant>
</Application>Morten la Cour

