August 2004 Archives

Wondering around CLI function support for XQuery

| No Comments | No TrackBacks

Am on designing something like CLI native function call support in our XQuery engine. Right now the code below runs with our cvs version.

XQueryCommand cmd = new XQueryCommand (); cmd.Compile (new StringReader (@" declare namespace math='System.Math'; declare function math:Log10($arg as xs:double) as xs:double external; <doc>{math:Log10(number(5.5))}</doc>")); cmd.Execute ((IXPathNavigable) null, XmlWriter.Create (Console.Out));

(sorry for those who disables JavaScript - '<' is incorrectly escaped.)

$ mono func.exe <doc>0.740362689494244</doc>

The original idea is from SAXON 8.0 that supports Java method invokation (and yes, it also looks like IXsltContextFunction). Currently my implementation immediately infers every external functions as native public static methods, and I don't like this design (especially "everything is CLI method" design, and the point that we must define every functions. It could be easy module imports).

I wonder how Microsoft developers think about XQuery extensions.

In short, there is no reason you cannot use RELAX NG in your web services theoretically. That's just the matter of insufficient implementation support of frameworks rather than spec matter.

As I implemented RelaxngDatatypeProvider in Commons.Xml.Relaxng.dll that supports XML Schema datatypes, you can use RELAX NG to represent "typed grammar". And it is possible for some grammars to map its items to runtime types (it is "theoretically" impossible to support runtime-type mapping for all kind of RELAX NG grammars. Read more for details). On the other hand: XML Schema is (also) not always mappable to runtime types. You can try xsd.exe with this simple example schema below and what useful classes it generates:

<xs:schema xmlns:xs=""></p> <p><xs:element name="Foo" type="myComplex" /> <xs:complexType name="myComplex"> <xs:choice> <xs:sequence> <xs:element name="element_A" type="xs:string" /> <xs:element name="element_B" type="xs:string" /> </xs:sequence> <xs:sequence> <xs:element name="element_C" type="xs:string" /> <xs:element name="element_D" type="xs:string" /> </xs:sequence> </xs:choice> </xs:complexType></p> <p></xs:schema>

(I haven't checked how JAXB 1.0 RI works here.)

The fact is: if you are lucky, your schema can be used for object mapping.

For RELAX NG side, we don't have runtime type mapping tool yet. At least, target grammar must be "deterministic" which is one of the reason why XML Schema is much complex than RELAX NG (XML Schema forces deterministic schema, while RELAX NG allows non-deterministic grammars). To implement it, first we have to create non-deterministic grammar detection utility (like RelaxMeter by Kohsuke Kawaguchi, which is, however, to detect ambiguity).

Once deterministic grammar detection got implemented, we can implement object mapping using RelaxngDatatypeProvider noted above.

But note that, for usual develoers, understanding "how we can create deterministic grammar" might be more difficult than understanding and believing XML Schema blindly (actually it won't be, since XML Schema has some extraneous buggy things like substitution groups). In fact am one of such people who don't fully understand how deterministic model detection will work on RELAX NG.

Am not interested in other discussion such like "New X won't be your solution, since every existing systems are based on old Y". We're those people who believed that .NET Framework makes development easier, while it had abandoned legacy stuff.

Hello, XQuery

| No Comments | No TrackBacks

I've been apart from cvs log history for a while, because I was XQuery pregnant.

using System.IO; using System.Xml; using System.Xml.Query;</p> <p>public class Test { public static void Main () { XQueryCommand cmd = new XQueryCommand (); cmd.Compile (new StringReader ("&lt;doc>hello, XQuery.&lt;/doc>")); cmd.Execute ((XmlResolver) null, new XmlTextWriter (System.Console.Out)); } }

_@r50 ~/tests/xml2_0/xquery
$ csc hello.cs -r:System.Data.SqlXml.dll -nologo

_@r50 ~/tests/xml2_0/xquery
$ ./hello
<doc>hello, XQuery.</doc>
_@r50 ~/tests/xml2_0/xquery
$ mono hello.exe
<doc>hello, XQuery.</doc>

Not sure when I can leave this hospital.


| No Comments | No TrackBacks

Today was the first day I tried to touch Nemerle. Inspired by Miguel's post, I created NemerleCodeProvider. There must be many mistakes caused by my ignorant of nemerle specification, but right now it would do something.

Since our xsd.exe can load external code provider, I tried my provider with xsd.exe.

$ cat test.xml <root> <foo/> <bar/> <baz/> </root></p> <p>$ xsd test.xml Written file .\test.xsd</p> <p>$ xsd /c /g:Nemerle.Contrib.NemerleCodeProvider,NemerleCodeProvider.dll Loaded custom generator type Nemerle.Contrib.NemerleCodeProvider,NemerleCodeProvider.dll . Written file .\test.n --> [*1]</p> <p>$ xsd /d /g:Nemerle.Contrib.NemerleCodeProvider,NemerleCodeProvider.dll Loaded custom generator type Nemerle.Contrib.NemerleCodeProvider,NemerleCodeProvider.dll . Written file .\test.n --> [*2]

[*1] test.n

[*2] test.n

The former test.n compiles, but curiously the latter one didn't compile. Today I have no clue (I tried to talk to nemerle community but could not get connected).


| No Comments | No TrackBacks

Yesterday I put XPathDocument2, saying that it could be easily made as editable. And (against my expectation) today I made another XML toy. Well, am mostly functioning just as a copy machine of (my) prior ones.

It is one day hacking, based on XPathEditableDocument I put last Thursday.