2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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 some improved implementations which resides
44   in Mono.Xml.Ext.dll.
45
46   [2.0] XmlDataSourceResolver <del>is not implemented as yet</del><ins>vanished</ins>.
47
48 **** XmlNameTable
49
50   NameTable is implemented, but also needs performance improvement.
51   Optimization hackings are welcome. There is also a <a 
52   href="http://bugzilla.ximian.com/show_bug.cgi?id=59537">bugzilla entry</a> 
53   for this matter.
54
55 **** XML Reader
56
57   XmlTextReader, XmlNodeReader and XmlValidatingReader are almost finished.
58
59         <ul>
60                 * All OASIS conformance test passes as Microsoft does. Some 
61                   W3C tests fail, but it looks better than Microsoft.
62                 * Entity expansion and its well-formedness check is incomplete.
63                   It incorrectly allows divided content models. It incorrectly
64                   treats its Base URI, so some dtd parse fails.
65                 * I won't add any XDR support on XmlValidatingReader. (I haven't
66                   ever seen XDR used other than Microsoft's BizTalk Server 2000,
67                   and Now they have 2002 with XML Schema support). If anyone
68                   contributes an implementation, it would be still nice.
69         </ul>
70
71   XmlTextReader and XmlValidatingReader should be faster than now. Currently
72   XmlTextReader looks nearly twice as slow as MS.NET, and XmlValidatingReader
73   (which uses this slow XmlTextReader) looks nearly three times slower. (Note
74   that XmlValidatingReader wouldn't be so slow as itself. It uses schema
75   validating reader and dtd validating reader.)
76
77
78 **** Some Advantages
79
80   The design of Mono's XmlValidatingReader is radically different from
81   that of Microsoft's implementation. Under MS.NET, DTD content validation
82   engine is in fact simple replacement of XML Schema validation engine.
83   Mono's DTD validation is designed fully separate and does validation
84   as normal XML parser does. For example, Mono allows non-deterministic DTD.
85
86   Another advantage of this XmlValidatingReader is support for *any* XmlReader.
87   Microsoft supports only XmlTextReader (this bug is fixed in .NET 2.0 beta,
88   taking shape of XmlReader.Create()).
89
90   <del>I added extra support interface named "IHasXmlParserContext", which is
91   considered in XmlValidatingReader.ResolveEntity(). </del><ins>This is now
92   made as internal interface.</ins> Microsoft failed to design XmlReader
93   so that XmlReader cannot be subtree-pluggable (i.e. wrapping use of other
94   XmlReader) since XmlParserContext shoud be supplied for DTD information
95   support (e.g. entity references cannot be expanded) and namespace manager.
96   (In .NET 2.0, Microsoft also supported similar to IHasXmlParserContext,
97   named IXmlNamespaceResolver, but it still does not provide DTD information.)
98
99   We also have RELAX NG validating reader (described later).
100
101
102 *** System.Xml.Schema
103
104 **** Summary
105
106   Basically it is completed. You can test how current schema validation engine
107   is complete (incomplete) by using standalone test module (see 
108   mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests).
109   At least in my box, msxsdtest fails only 30 cases with bugfixed catalog -
110   this score is better than that of Microsoft implementation. But instead,
111   we need performance boost. There should be many points to improve
112   schema compilation and validation.
113
114 **** Schema Object Model
115
116   Completed, except for some things to be fixed:
117
118         <ul>
119                 * Complete facet support. Currently some of them is missing.
120                   Recently David Sheldon is doing several fixes on them.
121                 * ContentTypeParticle for pointless xs:choice is incomplete
122                   (fixing this arose another bugs in compilation.
123                   Interestingly, MS.NET also fails around here, so it might
124                   be nature of ContentTypeParticle design)
125                 * Some derivation by restriction (DBR) handling is incorrect.
126         </ul>
127
128 **** Validating Reader
129
130   Basically this is implemented and actually its feature is complete,
131   but I have only did validation feature testing. So we have to write more 
132   tests on properties, methods, and events (validation errors).
133
134
135 *** System.Xml.Serialization
136
137   Lluis Sanchez is the maintainer of this namespace (as well as
138   System.Web.Services).
139
140   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. See "tools" section discussed later. There is also "sgen"
156   that is introduced in .NET 2.0.
157
158
159 *** System.Xml.XPath and System.Xml.Xsl
160
161   There are two XSLT implementations. One and historical implementation is
162   based on libxslt (aka Unmanaged XSLT). Now we uses fully implemented and
163   managed XSLT by default. To use Unmanaged XSLT, set MONO_UNMANAGED_XSLT
164   environment value (any value is acceptable).
165
166   As for Managed XSLT, we support msxsl:script.
167
168   It would be nice if we can support <a href="http://www.exslt.org/">EXSLT</a>.
169   <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>, 
170   but it is not successful because of System.Xml.Xsl design problem:
171
172         <ul>
173                 * In general, .NET's "extension objects" (including 
174                   msxsl:script) is not useful to return node-sets (MS XSLT
175                   implementation rejects just overriden XPathNodeIterator, 
176                   but accepts only their hidden classes. And are the same 
177                   in Mono though classes are different)
178
179                 * In .NET's extension object design, extension function name 
180                   is a valid method name that cannot contain some characters
181                   such as '-'. That is, implementing EXSLT in C# is impossible.
182         </ul>
183
184   So if we support EXSLT, it has to be done inside our System.XML.dll.
185   Microsoft developers are also aware of this problem and some of them wish
186   to have EXSLT support in WinFX (not whidbey). If anyone is interested
187   in it, it would be nice.
188
189   Our managed XSLT implementation is slower than MS XSLT for some kind of
190   stylesheets, and faster for some.
191
192
193 *** RELAX NG
194
195   I implemented an experimental RelaxngValidatingReader. It is still not
196   complete, for example some simplification stuff (see RELAX NG spec 
197   chapter 4; especially 4.17-19) and some constraints (especially 7.3).
198   See mcs/class/Commons.Xml.Relaxng/README for details.
199
200   Currently we have
201
202         <ul>
203                 * Custom datatype support. Right now, you can use XML schema
204                   datatypes ( http://www.w3.org/2001/XMLSchema-datatypes ) 
205                   as well as RELAX NG default datatypes (as used in relaxng.rng).
206
207                 * RELAX NG Compact Syntax support, though not yet stable.
208                   See Commons.Xml.Relaxng.Rnc.RncParser class.
209 </ul>
210
211
212 ** System.Xml v2.0
213
214   Microsoft released the first public beta version of .NET Framework 2.0,
215   available from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=916EC067-8BDC-4737-9430-6CEC9667655C&displaylang=en">MSDN</a>.
216   It contains several new classes.
217
218   There are two assemblies related to System.Xml v2.0; System.Xml.dll and
219   System.Data.SqlXml.dll. Now that System.Data.SqlXml.dll is little important.
220   It just contains only XQueryCommand class inside System.Xml.* namespace.
221   Most of the important part are in System.Xml.dll.
222
223   Note that .NET Framework is pre-release version, so they are subject
224   to change. Actually many of the pre-released classes vanished.
225
226   System.Xml 2.0 contains several features such as:
227
228         <ul>
229                 * new XPathNavigator members that supports editing XmlDocument
230                 * XmlReaderSettings, XmlWriterSettings and factory methods
231                 * Strongly typed XmlReader, XmlWriter and XPathNavigator.
232                 * XML Schema design changes
233                 * XSD Inference
234                 * Well-documented and improved XmlSerializer.
235                 * XSLT per-stylesheet assembly generator
236         </ul>
237
238 *** System.Xml 2.0
239
240 **** Summary
241
242   <a href="http://mono.ximian.com/class-status/mono-HEAD-vs-fx-2/class-status-System.Xml.html">
243   Here</a> is the latest status of mono's System.Xml 2.0.
244
245   Major remaining tasks are:
246
247         <ul>
248                 * binary content support on XmlReader
249                 * XmlValueConverter
250                 * XslCompiledTransform (not available in .NET FX 2.0 as yet)
251         </ul>
252
253   In general, System.Xml 2.0 bits are largely implemented.
254
255   I have some notes on things marked as "missing" in the above class status
256   page:
257
258         <ul>
259                 * XmlReader, XmlTextReader and XmlValidatingReader has
260                   many "missing bits", but ReadValueAsXxx() are obsoleted.
261                   They were now taken its place by ReadContentAsXxx() and
262                   ReadElementContentAsXxx() methods (those differences come
263                   from the basis of the methods: ReadElementString() or
264                   ReadString()).
265                 * In System.Xml.XPath - first, new features in XPathDocument
266                   are said as reverted. So I just commented out those new
267                   features that had been already implemented in mono.
268                   Other missing classes such as XPathEditableNavigator are
269                   obsolete and will vanish at the time of 2.0 RTM.
270                 * There are some security attributes. They are either way
271                   not applicable as yet, and actually currently corcompare
272                   ignores them. (So I already added some, but are ignored.)
273         </ul>
274
275 **** XmlReader/XmlWrier Factory methods
276
277   In .NET 2.0, XmlTextReader, XmlNodeReader, XmlValidatingReader are
278   obsolete and XmlReader.Create() is recommended (there is however no
279   alternative way to create XmlNodeReader). Similarly, there are
280   XmlWriter.Create() overloads.
281
282   Currently, Microsoft's XmlWriter.Create() is unstable and there will
283   be changes. So basically remaining XmlWriter.Create() is supposed to be
284   done after the next beta version of .NET 2.0.
285
286   Some of XmlReader.Create() overloads are implemented, with limited
287   XmlReaderSettings support.
288
289
290 **** Strongly typed XmlReader/XmlWriter
291
292   In .NET 2.0, XmlReader is supposed to support strongly-typed data reading.
293   They are based on W3C "XML Schema Datatypes" Recommendation and "XQuery 1.0
294   and XPath 2.0 Data Model" Working Draft.
295
296   Note that this W3C specification is just a Working Draft and there might
297   be incompatible changes for those strongly-typed API. For example, in the
298   latest version of the spec (as of November 2004), xs:QName is specified as
299   to have prefix, local name and namespace URI, while .NET XML classes just
300   treat it as XmlQualifiedName which does not contain prefix. So this part of
301   API might become obsolete or useless.
302
303   Some of XmlReader.ReadValueAsXxx() and XmlWriter.WriteValue() overloads are
304   implemented, though incompletely. They are based on internal XQueryConvert.
305
306
307 **** Sub-tree handling in XmlReader/XmlWriter/XPathNavigator
308
309   Currently XmlReader.ReadSubtree(), XmlWriter.WriteSubtree() and
310   XPathNavigator.ReadSubtree() are implemented, though not well-tested.
311   They are based on Mono.Xml.SubtreeXmlReader and
312   Mono.Xml.XPath.XPathNavigatorReader classes.
313
314
315 *** System.Xml.Schema 2.0
316
317   Since .NET 1.x is not so compliant with W3C XML Schema specification,
318   Microsoft had to redesign System.Xml.Schema classes. We also have to
319   change many things.
320
321         <ul>
322                 * It does not expose XmlSchemaDatatype as a type of an
323                   element or an attribute (except for obsolete members). 
324                   Primitive types are represented as XmlSchemaSimpleType 
325                   instances (thus there are ElementSchemaType, 
326                   AttributeSchemaType, BaseXmlSchemaType that replace some 
327                   existing properties). Note that XmlSchemaDatatype itself is 
328                   not deprecated as yet.
329
330                 * "XQuery 1.0 and XPath 2.0 Data Model" datatypes (such as
331                   xdt:dayTimeDuration) are newly supported. They are partially
332                   implemented yet.
333
334                 * schema structures are now bound in parent-child
335                   relationship. It is not yet implemented. With related to
336                   it, there seems bunch of schema compilation bugfixes.
337
338                 * XmlSchemaCollection is not used anymore to represent
339                   effective set of schemas. Instead, new XmlSchemaSet class
340                   is used. It should affect on schema compilation design.
341         </ul>
342
343
344 **** XSD Inference
345
346   In .NET 2.0, there is an XML Schema inference implementation. The API (or
347   implementation design) is not cool and Microsoft will make changes in
348   later version of beta or .NET Framework.
349
350 **** XmlSchemaValidator
351
352   It is (somewhat) exposed XML Schema validation functionality. It enables
353   developers to get expected particles and attributes. Actually it is
354   internally used to implement XmlReader.Create() with XmlSchemaSet.
355
356
357 *** System.Xml.XPath 2.0
358
359 **** Editable XPathNavigator
360
361   In System.Xml 2.0, XPathNavigator has many editing API (that used to be
362   "XPathEditableNavigator"). It enables developers to edit XmlDocument
363   (not for XPathDocument; it is read-only).
364
365   (In the early stage of .NET 2.0, XPathDocument is supposed to be editable.
366   Also, the new version of editable XPathNavigator had been already
367   implemented in Mono, as Mono.Xml.XPath.XPathEditableDocument.)
368
369
370 *** System.Xml.Xsl 2.0
371
372   There used to be System.Xml.Query.XsltCommand class, and it now disappeared
373   and it is said (by Microsoft developers) that there will be a class named
374   XslCompiledTransform - so it will be included in the next beta version.
375   It is regarded as the identical thing to XsltCommand.
376
377   XslCompiledtransform seems almost the same as System.Xml.Xsl.XslTransform,
378   but this class transforms documents twice to four times as fast as
379   XslTransform. Instead, stylesheet compilation is much slower, because
380   it generates compiled stylesheet assembly.
381
382
383
384 ** External assemblies for Mono 2.0
385
386 *** Mono.Xml.Ext
387
388   (<strong>IMPORTANT</strong>: There used to be System.Xml.Query.XQueryCommand
389   class that implemented XQuery, but now Microsoft dropped it for .NET 2.0.
390   So we moved them out to external assembly named Mono.Xml.Ext.dll, but I
391   haven't changed thing so much when I just extracted them. Thus, this
392   section is kept as is, and basically old stuff.)
393
394   Mono.Xml.Ext.dll contains mainly XQuery implementation, and some utility 
395   classes.
396
397   XQueryCommand implements XQuery. XQuery is a new face XML document
398   manipulation language (at least new face in .NET world). It is similar
399   to XSLT, but extended to support XML Schema based datatypes (and it is
400   not XML based langauge). It is similar to XPath, but it can construct
401   XML nodes. It has no complicated template resolution, but works like
402   functional languages.
403
404   Under MS.NET, XQuery implementation is mainly in System.Xml.Query and
405   MS.Internal.Xml.* namespaces. The implementation is mostly
406   in System.Xml.dll. It is also true to our System.Xml.dll. Our XQueryCommand
407   in System.Data.SqlXml.dll just invokes the actual XQuery processor
408   (Mono.Xml.XPath2.XQueryCommandImpl) which resides in System.Xml.dll via
409   reflection.
410
411   Currently we are not implementing MS.Internal.Xml.* classes. MS
412   implementation is based on an old version of the W3C specification, and
413   our implementation is currently based on 
414   <a href="http://www.w3.org/TR/2004/WD-xquery-20040723/">23 July 2004
415   version</a> (latest as of now) of the working draft.
416
417   XQuery implementation tasks are:
418
419         <ul>
420                 * XQuery syntax parser that parses xquery string to AST 
421                   (abstract syntax tree). -> partly not done.
422
423                 * XQuery AST compiler into static context -> partly not done.
424
425                 * XQuery (dynamic context) runtime = XQuery expression evaluator
426                   + sequence iterator. -> partly not done.
427
428                 * XPathItem data model and (mainly) conversion support.
429                   -> partly done.
430
431                 * Applied expression classes for XQuery/XPath 2.0 functions and
432                   operators. -> partly done.
433
434                 * Optimization, and design per-query assembly code generator (later)
435         </ul>
436
437   It already handles some queries, while major part implementation is missing
438   or buggy (like FLWOR, expressions for sequence type handling, built-in
439   function support etc.).
440
441
442 *** Relax NG and DSDL in Mono 1.2
443
444   Currently we support only RELAX NG as one part of ISO DSDL effort. There
445   is existing Schematron implementation (NMatrix Project: <a 
446   href="http://sourceforge.net/projects/dotnetopensrc/">
447   http://sourceforge.net/projects/dotnetopensrc/</a>). With a few changes,
448   it can be used with mono.
449   
450   We don't have multi-language based validation support, namely
451   Namespace-based Validation Dispatch Language (NVDL). To support unwrapping,
452   one special XmlReader implementation is required (other schema validation
453   support can be done by ReadSubtree()). Note that we had seen RELAX
454   Namespace, Modular Namespace (MNS) and Namespace Routing Language (NRL)
455   - that is, standardization effort is still ongoing (though NVDL looks
456   mostly the same as NRL).
457
458   In Mono 2.0, there are some improvements:
459
460         <ul>
461                 * RelaxngPattern.Compile() now provides error location.
462
463                 * RelaxngValidatingReader now supports "expected label
464                   collector" API; You can get name list of expected element
465                   names and attribute names by simulating validation.
466
467   In Mono 2.0, there might be improvements on Commons.Xml.Relaxng.
468
469         <ul>
470                 * The type of error should be kind of RelaxngGrammarException.
471
472                 * Right now there is no ambiguity detection implementation that
473                   would be useful for RelaxngPattern based xml serialization (if
474                   there is need).
475
476                 * Because of lack of ambiguity detection, there is no way to
477                   provide XmlMapping (XmlTypeMapping/XmlMemberMapping). But 
478                   If anyone is interested in such effort, integration with
479                   XmlSerializer would be interesting task.
480         </ul>
481
482
483 ** Tools
484
485 *** xsd.exe
486
487   See <a href="ado-net.html">ADO.NET page</a>.
488
489   Note that xsd.exe does not support XmlSchemaInference in System.Xml 2.0.
490
491 *** genxs.exe
492
493   genxs.exe is a custom XmlSerializer code generator. This is Mono exclusive 
494   advantage. See <a 
495   href="http://primates.ximian.com/~lluis/blog/archives/000120.html">Lluis's
496   description</a> and manpages for details. Code files are in mcs/tools/genxs.
497
498 *** sgen.exe
499
500   sgen.exe is an alternative XmlSerializer code generator which is based on
501   XmlSerializer.GenerateSerializer() written by Lluis. Code files are in
502   mcs/tools/sgen.
503
504 *** dtd2xsd.exe
505
506   It is a tiny tool that enables conversion from DTD structure to XML Schema.
507   You need an XML instance, not DTD file itself (since basic XmlTextReader has
508   no feature to read external DTD resource itself). It runs only under mono.
509
510 ** Miscellaneous
511
512 *** Mutual assembly dependency
513
514   Sometimes I hear complain about System.dll and System.Xml.dll mutual
515   dependency: System.dll references to System.Xml.dll (e.g. 
516   System.Configuration.ConfigXmlDocument extended from XmlDocument), while 
517   System.Xml.dll vice versa (e.g. XmlUrlResolver.ResolveUri takes System.Uri).
518   Since they are in public method signatures, so at least we cannot get rid
519   of these mutual references.
520
521   Nowadays System.Xml.dll is built using incomplete System.dll (lacking
522   System.Xml dependent classes such as ConfigXmlDocument). Full System.dll
523   is built after System.Xml.dll is done.
524
525   Note that you still need System.dll to run mcs.
526
527
528   Atsushi Eno <atsushi@ximian.com>
529   last updated 12/16/2004
530