2004-09-02 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / web / xml-classes
1 * XML Classes Status and Tasks
2
3 ** Abstract
4
5   XML library is used by several areas of Mono such as ADO.NET and XML 
6   Digital Signature (xmldsig). Here I write about System.Xml.dll and
7   related tools. This page won't include any classes which are in other
8   assemblies such as XmlDataDocument.
9
10   Note that current corlib has its own XML parser class (Mono.Xml.MiniParser).
11
12   Basically System.XML.dll feature is almost finished, so I write this
13   document mainly for bugs and improvement hints.
14
15 ** Status
16
17 *** System.Xml namespace
18
19
20 **** Document Object Model (Core)
21
22   DOM implementation has finished and our DOM implementation scores better
23   than MS.NET as to the NIST DOM test results (it is ported by Mainsoft
24   hackers and in our unit tests).
25
26 **** Xml Writer
27
28   Here XmlWriter almost equals to XmlTextWriter. If you want to see
29   another implementation, check XmlNodeWriter.cs and DTMXPathDocumentWriter.cs
30   in System.XML sources.
31
32   XmlTextWriter is completed, though it looks a bit slower than MS.NET (I
33   tried 1.1).
34
35 **** XmlResolver
36
37   XmlUrlResolver is implemented.
38
39   XmlSecureResolver, which is introduced in MS .NET Framework 1.1 is basically
40   implemented, but it requires CAS (code access security) feature. We need to
41   fixup this class after ongoing CAS effort works.
42
43   You might also be interested in an improved <a href="http://codeblogs.ximian.com/blogs/benm/archives/000039.html">XmlCachingResolver</a> by Ben Maurer. 
44   If even one time download is not acceptable, you can use <a href="http://primates.ximian.com/~atsushi/XmlStoredResolver.cs">this one</a>.
45
46   [2.0] XmlDataSourceResolver is not implemented as yet.
47
48 **** XmlNameTable
49
50   NameTable is implemented, but also needs performance improvement.
51   It affects on the whole XML processing performance so much.
52   Optimization hackings are welcome. There is also a <a 
53   href="http://bugzilla.ximian.com/show_bug.cgi?id=59537">bugzilla entry</a> 
54   for this matter.
55
56 **** XML Reader
57
58   XmlTextReader, XmlNodeReader and XmlValidatingReader are almost finished.
59
60         <ul>
61                 * All OASIS conformance test passes as Microsoft does. Some 
62                   W3C tests fail, but it looks better.
63                 * Entity expansion and its well-formedness check is incomplete.
64                   It incorrectly allows divided content models. It incorrectly
65                   treats its Base URI, so some dtd parse fails.
66                 * I won't add any XDR support on XmlValidatingReader. (I haven't
67                   ever seen XDR used other than Microsoft's BizTalk Server 2000,
68                   and Now they have 2002 with XML Schema support). If anyone
69                   contributes an implementation, it would be still nice.
70         </ul>
71
72   XmlTextReader and XmlValidatingReader should be faster than now. Currently
73   XmlTextReader looks nearly twice as slow as MS.NET, and XmlValidatingReader
74   (which uses this slow XmlTextReader) looks nearly three times slower. (Note
75   that XmlValidatingReader wouldn't be so slow as itself. It uses schema
76   validating reader and dtd validating reader.)
77
78
79 **** Some Advantages
80
81   The design of Mono's XmlValidatingReader is radically different from
82   that of Microsoft's implementation. Under MS.NET, DTD content validation
83   engine is in fact simple replacement of XML Schema validation engine.
84   Mono's DTD validation is designed fully separate and does validation
85   as normal XML parser does. For example, Mono allows non-deterministic DTD.
86
87   Another advantage of this XmlValidatingReader is support for *any* XmlReader.
88   Microsoft supports only XmlTextReader (this bug is fixed in .NET 2.0 beta,
89   taking shape of XmlReader.Create()).
90
91   <del>I added extra support interface named "IHasXmlParserContext", which is
92   considered in XmlValidatingReader.ResolveEntity(). </del><ins>This is now
93   made as internal interface.</ins> Microsoft failed to design XmlReader
94   so that XmlReader cannot be subtree-pluggable (i.e. wrapping use of other
95   XmlReader) since XmlParserContext shoud be supplied for DTD information
96   support (e.g. entity references cannot be expanded) and namespace manager.
97   (In .NET 2.0, Microsoft also supported similar to IHasXmlParserContext,
98   named IXmlNamespaceResolver, but it still does not provide DTD information.)
99
100   We also have RELAX NG validating reader (described later).
101
102
103 *** System.Xml.Schema
104
105 **** Summary
106
107   Basically it is completed. You can test how current schema validation engine
108   is complete (incomplete) by using standalone test module (see 
109   mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests).
110   At least in my box, msxsdtest fails only 30 cases with bugfixed catalog -
111   this score is better than that of Microsoft implementation. But instead,
112   we need performance boost. There should be many points to improve
113   schema compilation and validation.
114
115 **** Schema Object Model
116
117   Completed, except for some things to be fixed:
118
119         <ul>
120                 * Complete facet support. Currently some of them is missing.
121                   Recently David Sheldon is doing several fixes on them.
122                 * ContentTypeParticle for pointless xs:choice is incomplete
123                   (fixing this arose another bugs in compilation.
124                   Interestingly, MS.NET also fails around here, so it might
125                   be nature of ContentTypeParticle design)
126                 * Some derivation by restriction (DBR) handling is incorrect.
127         </ul>
128
129 **** Validating Reader
130
131   Basically this is implemented and actually its feature is complete,
132   but I have only did validation feature testing. So we have to write more 
133   tests on properties, methods, and events (validation errors).
134
135
136 *** System.Xml.Serialization
137
138   Lluis rules ;-)
139
140   Well, in fact XmlSerializer is almost finished and is on bugfix phase.
141
142   However, we appliciate more tests. Please try 
143   
144         <ul>
145                 * System.Web.Services to invoke SOAP services.
146                 * xsd.exe and wsdl.exe to create classes.
147         </ul>
148
149   And if any problems were found, please file it to bugzilla.
150
151   Lluis also built interesting standalone test system placed under
152   mcs/class/System.Web.Services/Test/standalone.
153
154   You might also interested in "genxs", which enables you to create custom
155   XML serializer. This is not included in Microsoft.NET. 
156   See <a 
157   href="http://primates.ximian.com/~lluis/blog/archives/000120.html">here</a>
158   and manpages for details. Code files are in mcs/tools/genxs.
159
160   Lluis also created "sgen", that based on XmlSerializer.GenerateSerializer().
161   Code files are in mcs/tools/sgen.
162
163 *** System.Xml.XPath and System.Xml.Xsl
164
165   There are two XSLT implementations. One and historical implementation is
166   based on libxslt (aka Unmanaged XSLT). Now we uses fully implemented and
167   managed XSLT by default. To use Unmanaged XSLT, set MONO_UNMANAGED_XSLT
168   environment value (any value is acceptable).
169
170   As for Managed XSLT, we support msxsl:script.
171
172   It would be nice if we can support <a href="http://www.exslt.org/">EXSLT</a>.
173   <a href="http://msdn.microsoft.com/WebServices/default.aspx?pull=/library/en-us/dnexxml/html/xml05192003.asp">Microsoft has tried to do some of them</a>, 
174   but it is not successful because of System.Xml.Xsl design problem:
175
176         <ul>
177                 * In general, .NET's "extension objects" (including 
178                   msxsl:script) is not useful to return node-sets (MS XSLT
179                   implementation rejects just overriden XPathNodeIterator, 
180                   but accepts only their hidden classes. And are the same 
181                   in Mono though classes are different)
182
183                 * In .NET's extension object design, extension function name 
184                   is a valid method name that cannot contain some characters
185                   such as '-'. That is, implementing EXSLT in C# is impossible.
186         </ul>
187
188   So if we support EXSLT, it has to be done inside our System.XML.dll.
189   Microsoft developers are also aware of this problem and some of them wish
190   to have EXSLT support in WinFX (not whidbey). If anyone is interested
191   in it, it would be nice.
192
193   Our managed XSLT implementation is slower than MS XSLT for some kind of
194   stylesheets, and faster for some.
195
196
197 *** RELAX NG
198
199   I implemented an experimental RelaxngValidatingReader. It is still not
200   complete, for example some simplification stuff (see RELAX NG spec 
201   chapter 4; especially 4.17-19) and some constraints (especially 7.3).
202   See mcs/class/Commons.Xml.Relaxng/README for details.
203
204   Currently we have
205
206         <ul>
207                 * Custom datatype support. Right now, you can use XML schema
208                   datatypes ( http://www.w3.org/2001/XMLSchema-datatypes ) 
209                   as well as RELAX NG default datatypes (as used in relaxng.rng).
210
211                 * RELAX NG Compact Syntax support, though not yet stable.
212                   See Commons.Xml.Relaxng.Rnc.RncParser class.
213 </ul>
214
215
216 ** System.Xml v2.0
217
218   Microsoft released the first public beta version of .NET Framework 2.0,
219   available from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=916EC067-8BDC-4737-9430-6CEC9667655C&displaylang=en">MSDN</a>.
220   It contains several new classes.
221
222   There are two assemblies related to System.Xml v2.0; System.Xml.dll and
223   System.Data.SqlXml.dll. Now that System.Data.SqlXml.dll is little important.
224   It just contains only XQueryCommand class inside System.Xml.* namespace.
225   Most of the important part are in System.Xml.dll.
226
227   Note that .NET Framework is pre-release version, so they are subject
228   to change. Actually many of the pre-released classes vanished.
229
230   System.Xml 2.0 contains several features such as:
231
232         <ul>
233                 * new XPathNavigator <del>and XPathDocument</del><ins>XPathDocument is <a href="http://blogs.msdn.com/dareobasanjo/archive/2004/08/25/220251.aspx">being reverted</a></ins>
234                 * XmlReaderSettings, XmlWriterSettings and factory methods
235                 * Strongly typed XmlReader and XmlWriter.
236                 * XML Schema design changes
237                 * XSD Inference
238                 * Well-documented and improved XmlSerializer.
239                 * XQuery execution engine
240                 * XQuery and XSLT per-stylesheet assembly generator
241         </ul>
242
243 *** System.Xml 2.0
244
245 **** XmlReader/XmlWrier Factory methods
246
247   In .NET 2.0, XmlTextReader, XmlNodeReader, XmlValidatingReader are
248   obsolete and XmlReader.Create() is recommended (there is however no
249   alternative way to create XmlNodeReader). Similarly, there are
250   XmlWriter.Create() overloads.
251
252   Currently, Microsoft's XmlWriter.Create() is unreliable and maybe there
253   will be changes. So basically XmlWriter.Create() is supposed to be done
254   after the next beta version of .NET 2.0.
255
256   Some of XmlReader.Create() overloads are implemented, with limited
257   XmlReaderSettings support.
258
259
260 **** Typed XmlReader/XmlWriter
261
262   In .NET 2.0, XmlReader is supposed to support strongly-typed data reading.
263   They are based on W3C "XML Schema Datatypes" Recommendation and "XQuery 1.0
264   and XPath 2.0 Data Model" Working Draft.
265
266   Some of XmlReader.ReadValueAsXxx() and XmlWriter.WriteValue() overloads are
267   implemented, though incompletely. They are based on internal XQueryConvert.
268
269
270 **** Sub-tree handling in XmlReader/XmlWriter/XPathNavigator
271
272   Currently XmlReader.ReadSubtree(), XmlWriter.WriteSubtree() and
273   XPathNavigator.ReadSubtree() are implemented, though not well-tested.
274   They are based on Mono.Xml.SubtreeXmlReader and
275   Mono.Xml.XPath.XPathNavigatorReader classes.
276
277
278 *** System.Xml.Schema 2.0
279
280   Since .NET 1.x is not so compliant with W3C XML Schema specification,
281   Microsoft had to redesign System.Xml.Schema classes. We also have to
282   change many things.
283
284   1) It does not expose XmlSchemaDatatype anymore (except for obsolete
285   members). Primitive types are represented as XmlSchemaSimpleType
286   instances (thus there are ElementSchemaType, AttributeSchemaType,
287   BaseXmlSchemaType that replace some existing properties).
288
289   2) "XQuery 1.0 and XPath 2.0 Data Model" datatypes (such as
290   xdt:dayTimeDuration) are newly supported. They are partially implemented
291   yet. This task is partly done.
292
293   3) schema structures are now bound in parent-child relationship. It is
294   not yet implemented. With related to it, there seems bunch of schema
295   compilation bugfixes.
296
297   4) XmlSchemaCollection is not used anymore to represent effective set of
298   schemas. Instead, new XmlSchemaSet class is used. It should affect on
299   schema compilation design. In fact, I've implemented XmlSchemaCollection
300   as more conformant to W3C specification, but there are still many changes
301   required. This task is partly done.
302
303
304 **** XSD Inference
305
306   In .NET 2.0, there is an XML Schema inference implementation. Now that
307   XmlSchemaSet is basically implemented, it can be separately done by anyone.
308   Volunteer efforts are welcome here.
309
310
311 *** System.Xml.XPath 2.0
312
313 **** Editable XPathDocument
314
315   <del>
316   in .NET 2.0 XPathDocument is supposed to be editable. Currently we provide
317   fast document table model based implementation (DTMXPathNavigator), but
318   by that design change, we (and they) cannot provide fast read only
319   XPathNavigator from XPathDocument anymore.
320   </del><ins>
321   It is being reverted to the original (.NET 1.x) XPathDocument. We still have
322   them, but we'll revert them too in the future. So our XPathDocument will be still faster one.
323   </ins>
324
325   Currently, new XPathDocument implementation is provided. The actual
326   implementation is Mono.Xml.XPath.XPathDocument2, that is simple dom-like
327   tree model. XPathDocument2 implements the same interfaces as XPathDocument
328   does. And XPathDocument delegates most of the methods to that class (for
329   example, XPathDocument.CreateEditor() calls XPathDocument2.CreateEditor()).
330
331   Currently Mono.Xml.XPath.XPathDocument2 is unstable (it does not pass
332   the standalone XSLT tests unlike existing DTMXPathDocument does). So
333   it did not replace existing XPathDocument implementation, but you can use
334   new implementation by explicitly setting environment value
335   USE_XPATH_DOCUMENT_2 = yes. Currently it supports (well, is supposed 
336   to support) basic editor feature such as AppendChild(). Other members
337   are untested (such as RejectChanges()).
338
339 **** extra stuff - XPathEditableDocument
340
341   Currently we provide another IXPathEditable; XPathEditableDocument. That is
342   based on the idea that handles XmlDocument as editor target. It is
343   implemented as Mono.Xml.XPath.XPathEditableDocument. We might provide this
344   class as extra set (might be different mono-specific XML assembly).
345
346
347 **** System.Xml.XQuery
348
349   In this namespace, there are two significant classes. XsltCommand and 
350   XQueryCommand.
351
352   XsltCommand implements XSLT transformation. It is almost the same as
353   System.Xml.Xsl.XslTransform, but this class transforms documents twice
354   to four times as fast as XslTransform. Instead, stylesheet compilation
355   is much slower, because it generates compiled stylesheet assembly.
356
357   XQueryCommand implements XQuery. XQuery is a new face XML document
358   manipulation language (at least new face in .NET world). It is similar
359   to XSLT, but extended to support XML Schema based datatypes (and it is
360   not XML based langauge). It is similar to XPath, but it can construct
361   XML nodes. It has no complicated template resolution, but works like
362   functional languages.
363
364   Under MS.NET, XQuery implementation is mainly in System.Xml.Query and
365   MS.Internal.Xml.* namespaces. The implementation is mostly
366   in System.Xml.dll. It is also true to our System.Xml.dll. Our XQueryCommand
367   in System.Data.SqlXml.dll just invokes the actual XQuery processor
368   (Mono.Xml.XPath2.XQueryCommandImpl) which resides in System.Xml.dll via
369   reflection.
370
371   Currently we are not implementing MS.Internal.Xml.* classes. MS
372   implementation is based on an old version of the W3C specification, and
373   our implementation is currently based on 
374   <a href="http://www.w3.org/TR/2004/WD-xquery-20040723/">23 July 2004
375   version</a> (latest as of now) of the working draft.
376
377   XQuery implementation tasks are:
378
379         <ul>
380                 * XQuery syntax parser that parses xquery string to AST 
381                   (abstract syntax tree). -> partly not done.
382
383                 * XQuery AST compiler into static context -> partly not done.
384
385                 * XQuery (dynamic context) runtime = XQuery expression evaluator
386                   + sequence iterator. -> partly not done.
387
388                 * XPathItem data model and (mainly) conversion support.
389                   -> partly done.
390
391                 * Applied expression classes for XQuery/XPath 2.0 functions and
392                   operators. -> partly done.
393
394                 * Optimization, and design per-query assembly code generator (later)
395         </ul>
396
397   It already handles some queries, while major part implementation is missing
398   or buggy (like FLWOR, expressions for sequence type handling, built-in
399   function support etc.).
400
401
402 *** Relax NG and DSDL in Mono 1.2
403
404   Currently we support only RELAX NG as one part of ISO DSDL effort. There
405   is existing Schematron implementation (NMatrix Project: <a 
406   href="http://sourceforge.net/projects/dotnetopensrc/">
407   http://sourceforge.net/projects/dotnetopensrc/</a>). With a few changes,
408   it can be used with mono.
409   
410   We also don't have multi-language based validation support, namely
411   Namespace-based Validation Dispatch Language (NVDL). To support unwrapping,
412   one special XmlReader implementation is required (other schema validation
413   support can be done by ReadSubtree()). Note that we had seen RELAX
414   Namespace, Modular Namespace (MNS) and Namespace Routing Language (NRL)
415   - that is, standardization effort is still ongoing (though NVDL looks
416   mostly the same as NRL).
417
418   In Mono 1.2, there might be improvements on Commons.Xml.Relaxng.
419
420         <ul>
421                 * Currently RelaxngPattern.Compile() provides cheap compilation
422                   error information. At least it can provide error location.
423                   Also, the type of error should be kind of 
424                   RelaxngGrammarException.
425
426                 * Right now there is no ambiguity detection implementation that
427                   would be useful for RelaxngPattern based xml serialization (if
428                   there is need).
429
430                 * Because of lack of ambiguity detection, there is no way to
431                   provide XmlMapping (XmlTypeMapping/XmlMemberMapping). But 
432                   If anyone is interested in such effort, integration with
433                   XmlSerializer would be interesting task.
434         </ul>
435
436
437 ** Tools
438
439 *** xsd.exe
440
441   See <a href="ado-net.html">ADO.NET page</a>.
442
443
444 ** Miscellaneous
445
446 *** Mutual assembly dependency
447
448   Sometimes I hear complain about System.dll and System.Xml.dll mutual
449   dependency: System.dll references to System.Xml.dll (e.g. 
450   System.Configuration.ConfigXmlDocument extended from XmlDocument), while 
451   System.Xml.dll vice versa (e.g. XmlUrlResolver.ResolveUri takes System.Uri).
452   Since they are in public method signatures, so at least we cannot get rid
453   of these mutual references.
454
455   Nowadays System.Xml.dll is built using incomplete System.dll (lacking
456   System.Xml dependent classes such as ConfigXmlDocument). Full System.dll
457   is built after System.Xml.dll is done.
458
459   Note that you still need System.dll to run mcs.
460
461
462   Atsushi Eno <asushi@ximian.com>
463   last updated 09/02/2004
464