Wednesday, June 14, 2006

What do you do if the application you develop using .NET CF requires you to transform XML with some XSL and you know that .NET CF doesn't support that? You are not completelly out of luck here. Did you know that the native Microsoft XML Parser MSXML2 is included in all Windows Mobile devices and in most custom Windows CE devices as well? Of course it's a COM component, but CF v2 has added support for COM interop. So, here are 2 steps to enable MSXML2 usage in your CF application:

1. Open Visual Studio 2005 Command prompt, navigate to the ..\Include\Armv4i directory of the Windows Mobile SDK, and execute the following line:

midl msxml2.idl 

The result of this execution will be creation of the msxml2.tlb library.

2. Copy the msxml2.tlb into your project's directory and add the reference to it by browsing. The Visual Studio will recognize that this is a type libabry and will generate the MSXML2 interop assembly.

Now you can create an instance of the DOMDocumentClass and use its XSL transformation functionality:

MSXML2.DOMDocument doc = new MSXML2.DOMDocumentClass();
// Load XML document.
doc.load(“customer.xml"));

MSXML2.DOMDocument xsl = new MSXML2.DOMDocumentClass();
// Load XSLT document.
xsl.load(“customer.xslt"));
// Transform XML data.
string temp = doc.transformNode(xsl);

6/14/2006 3:12:38 AM (GMT Daylight Time, UTC+01:00)  #     |