xml-classes 18 KB

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