Finding and using a .Net class

Using (or providing) Microsoft.NET Classes
Post Reply
User avatar
StephenTaylor
Posts: 31
Joined: Thu May 28, 2009 8:20 am

Finding and using a .Net class

Post by StephenTaylor »

In another interpreter I have been using Microsoft XML services exposed as an OCX:

      '∆XSL' ⎕WI 'Create' 'Msxml2.DOMDocument.6.0'

and as a first guess tried

      ⎕USING,←⊂'msxml2.dll'
xml←⎕NEW DOMDocument

getting a value error, and the autocomplete revealed nothing following ⎕NEW that looks like it might be an XML document object.

A quick squint into this forum found PGilbert's

      ⎕USING←⊂'System.Xml,System.Xml.dll'
xml←⎕NEW XmlDocument
xml.Load ⊂'C:\blah\blah\blah.xml'

but xml lacks any method that looks like an XSL Transform. I reached this conclusion by trying autocomplete with all 26 majuscules. Workspace Explorer shows me no detail for xml, and autocomplete found me nothing that looks like property or method lists. So first question:

Q1. How to see the methods etc of an instance of a .Net class?

The Dot Net Interface Guide seems to answer this. First it warns:

To enable the display of Metadata in the Workspace Explorer, you must have the Type Libraries option of the View menu checked.

But neither the View menu of the Dyalog window nor of the Ws Explorer has a Type Libraries option on it.

Q2. How to enable the display of Metadata in the Workspace Explorer?

Perhaps that's no longer necessary. The Workspace Tree includes a top-level folder for TypeLibs, also another for MetaData.

The Dot Net Interface Guide counsels how to browse the .Net classes, by right clicking the MetaData folder icon, picking Load and navigating to open the DLL of one's choice. Repeated tries with this produce no change in the Workspace Tree.

Q3. How to browse the metadata of a selected DLL?

Happily, the TypeLibs/Registered Libraries folder is packed with children. Among them I find "Microsoft XML, version 2.0", right-click for a context menu, pick load, and see the metadata appear in TypeLibs/Load Libraries. This looks to be what I want.

The Dot Net Interface Guide tells me to set ⎕USING, ideally with the .Net namespace and filename, but if necessary with the filename. If "Microsoft XML, version 2.0" is the .Net namespace it won't do for ⎕USING, which is delimited by commas. But the filename is given clearly in Windows Explorer and a C:\windows\msxml2.dll awaits me. So

      )CLEAR
clear ws
⎕USING,←⊂'C:\WINDOWS\msxml2.dll'
xml←⎕NEW IXMLDOMDocument
VALUE ERROR
xml←⎕NEW IXMLDOMDocument

Q4. How to construct an instance of a .Net class described in the TypeLibs metadata?

Unanswered these questions leave me in an odd situation. I can make an XmlDocument instance but not see what it does. I can see what the IXMLDOMDocument class does, but not use it. What am I missing?

John Scholes: "I think, sir, you'll find that it does have a use and it will fucking bang things."

SJT
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Finding and using a .Net class

Post by Morten|Dyalog »

Hi Stephen!

The easy question first: Finding metadata about a .NET object:

Code: Select all

      xml.⎕nl -2 ⍝ Fields and Properties
Attributes  BaseURI  ChildNodes  DocumentElement  DocumentType  FirstChild  HasChildNodes  Implementation  InnerText  InnerXml  IsReadOnly  Item  LastChild  LocalName  ...etc...
      xml.⎕nl -3 ⍝ Methods
AppendChild  Clone  CloneNode  CreateAttribute  CreateCDataSection  CreateComment  CreateDocumentFragment  CreateDocumentType  CreateElement  CreateEntityReference  ...etc...


But even with the above, you probably want to look at the Microsoft documentation on MSDN... Just enter the class name in Google and follow the links to MSDN.

Regarding the questions about OCX's adn XSLT... I need to do a little research, I'll be back.
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Finding and using a .Net class

Post by PGilbert »

On a preliminary basis, System.Xml.dll seems to be the correct assembly to do what you are looking for. To explore an assembly I like to use the .Net reflector http://www.red-gate.com/products/dotnet-development/reflector/. There is the function NOE that I have posted here to have a look at the methods, properties and events of a Dyalog .Net Object with their constructor(s).
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

Re: Finding and using a .Net class

Post by StefanoLanzavecchia »

First of all about your Q3: msxml2 is a COM component not a .NET one. So
      ⎕USING
is not of much use. (Plus the syntax you used is wrong, because the DLL name is supposed to be the second part of a comma-separated string, but that doesn't really matter, as we just discovered).

For COM components you go the old way: you register them with regsvr32 (but I would expect msxml2 to be already registered since the OS and its ancillary components use it) and off you go. There was a good article in Vector by Barman who showed how to use it from Dyalog APL.

XSLT transforms in .NET are accomplihsed via namespace http://msdn.microsoft.com/en-us/library/system.xml.xsl(v=vs.110).aspx. The interesting class is http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform(v=vs.110).aspx and its
      Transform
method has overloads for all the possible input and output sources you can think of. Have fun!
User avatar
StephenTaylor
Posts: 31
Joined: Thu May 28, 2009 8:20 am

Re: Finding and using a .Net class

Post by StephenTaylor »

Thanks for all the leads. The crucial tip was to look at System.Xml in the MSDN documentation. You might have expected someone who wants to use a .Net assembly to go there first. Well, it's been too long. (And it's good to be back.)

For the record, here is all you need to run a XSL Transform across a list of files:

      ⎕USING,←⊂'System.Xml.Xsl,System.Xml.dll'
proc←⎕NEW XslCompiledTransform
proc.Load⊂xslpath
proc.Transform¨⊂[2]stems∘.,'.xml' '.html'

If anyone is interested in the larger context: I've been taking HTMs exported from Microsoft Word and stripping them into clean, valid, tidy HTML suitable for a colleague to edit mostly in the SeaMonkey WYSIWYG editor, with occasional dives into the raw markup. (The latter not to be attempted with Microsoft-generated HTML.) Besides a custom XSL I've also used HTML Tidy and a handful of RegEx replaces courtesy of the very nifty ⎕R -- most impressed with this.

Still unclear to me what if anything Workspace Explorer will do for me with a .Net assembly.
Vince|Dyalog
Posts: 439
Joined: Wed Oct 01, 2008 9:39 am

Re: Finding and using a .Net class

Post by Vince|Dyalog »

Hi Stephen,

Workspace Explorer gives you the ability to browse the .net metadata of the assembly.

As Pierre has said, there are other ways and other products to look at this as well.

Regards,

Vince
Post Reply