Byte Chomper
Andrew Gordon's weblog

Silverlight 2.0 no xsl

July 3, 2008 02:05 by andrew

love Silverlight 2.0, it just makes sense to a c# hack such as myself but with aspirations of reducing server side load to a minimum I had the bright idea of moving XSL operations to the client... All I need is the compact runtime XSL libraries... Hmm... I've got rich XML support... Where's the bloody XSL??

Please if anyone finds it call me a muppet and point me in the right direction. Still it's an opportunity for a workaround (otherwise known as hack :)

Simple task: leverage Javascript XSL capabilities within Silverlight in an interesting way.

/// Internet Explorer   protected override ScriptObject LoadXml(string xml)    {        ScriptObject scriptObj = HtmlPage.Window.CreateInstance("ActiveXObject", new object[] { "Microsoft.XMLDOM" });        if ((bool)scriptObj.Invoke("loadXml", new object[] { xml }))        {            return scriptObj;        }        else        {            throw new ArgumentException("XmlDocument could not be generated from string", "xml");        }    }   /// Mozilla/Safari   protected override ScriptObject LoadXml(string xml)    {        ScriptObject scriptObj = HtmlPage.Window.CreateInstance("DOMParser", null);        return scriptObj.Invoke("parseFromString", new object[] { xml, "text/xml" }) as ScriptObject;    }

/// Internet Explorer   public override string Transform(string xmlData)    {        string transformationResult = string.Empty;        ScriptObject xmlObj = LoadXml(xmlData);        transformationResult = xmlObj.Invoke("transformNode", this.XslDataObj) as string;        return transformationResult;    }   /// Mozilla/Safari   public override string Transform(string xmlData)    {        string transformationResult = String.Empty;        ScriptObject xmlObj = LoadXml(xmlData);        ScriptObject processor = HtmlPage.Window.CreateInstance("XSLTProcessor");        processor.Invoke("importStylesheet", new object[] { this.XslDataObj });        ScriptObject processorResult = processor.Invoke("transformToDocument", new object[] { xmlObj, HtmlPage.Window.GetProperty("document") }) as ScriptObject;        ScriptObject serializer = HtmlPage.Window.CreateInstance("XMLSerializer");        transformationResult = serializer.Invoke("serializeToString", new object[] { processorResult }) as string;        return transformationResult;    }

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 1.8 by 2719 people

  • Currently 1.772846/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .net | c# | Silverlight
Actions: E-mail | Permalink | Comments (617) | Comment RSSRSS comment feed

Silverlight beta 2: Cross-domain quirks

June 9, 2008 22:46 by Andrew

I have been trying to quickly integrate Silverlight 2.0 B2 with my current production environment. Previous Silverlight1.0 cross-domain calls had been hacked together with AJAX proxies and the like, but this is all out of the box with the new version...

I've already got crossdomain.xml files littered through my services for Flash access so I thought this would be easy. Consider the following:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>

Seems valid enough, but beware - Microsoft Silverlight does not fully support the cross-domain-policy at this time. The 'to-ports' attribute will prevent access to the hosting domain and block the cross-site call. Damn, have to get some clientaccesspolicy.xml files done

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 3.0 by 235 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .net | c# | Silverlight
Actions: E-mail | Permalink | Comments (490) | Comment RSSRSS comment feed

Silverlight 2.0 Beta 2 out

June 6, 2008 22:50 by Andrew

Checkout Scottgu's blog for more info

http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 3.0 by 130 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Silverlight
Actions: E-mail | Permalink | Comments (494) | Comment RSSRSS comment feed