Sunday, April 20, 2008

How-to get the XML representacion of a DSL Model Element

Today I had to find out how to get the XML representacion of a DSL Model Element. Here you have an extension method for Model Elements (mels) that gets the concrete serializer using the Domain XML Serializer Directory and the Domain Class Id of the target Model Element (mel).

        public static string GetXML(this ModelElement mel)
{
StringBuilder xml = new StringBuilder();

DomainXmlSerializerDirectory directory = new DomainXmlSerializerDirectory();
directory.AddBehavior(CoreDesignSurfaceSerializationBehavior.Instance);
directory.AddBehavior(<#Yours DSL Serialization Behavior goes here #>.Instance);
// Gets the serializer of the Mel
            DomainClassXmlSerializer serializer = directory.GetSerializer(mel.GetDomainClass().Id);

if (serializer != null)
{
using (XmlWriter writer = XmlWriter.Create(new StringWriter(xml)))
{
serializer.Write(new SerializationContext(directory), mel, writer);
}
}
else
{
Trace.TraceWarning(Resources.UnableToGetSerializer, mel.GetType().Name);
}

return xml.ToString();
}
HTH,
Adrian

Comments:
婚禮顧問公司需要找網站設計公司來做網站,並且配合廣告設計的事項。
 
aguante python !!
 
Hello guys im new on yous forum nice to see you all my website: [url=http://google.com]google[/url]
 
http://www.kuronekocon.org/forum/index.php?action=profile;u=25565
I just got my laptop 1 week ago and now i have viruses. I don't know what to do i'm only 13. Anyone? Please! i need this laptop for school and 12 of my projects got deleted. Tell me what to do and all i go on is youtube google myspace and face-book someone tell me what to do i was going to get virus protection today but now its too late!
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?